|
|
|
@ -18,12 +18,14 @@ |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
// ### TO DO: general issues:
|
|
|
|
|
// - power management
|
|
|
|
|
// - interrupt handling (direct/indirect)
|
|
|
|
|
// - pin/mux-handling (just overall concept due to project dependency)
|
|
|
|
|
// - multiple instances capability
|
|
|
|
|
// - slave functionality
|
|
|
|
|
/*
|
|
|
|
|
### TO DO: general issues: |
|
|
|
|
- power management |
|
|
|
|
- interrupt handling (direct/indirect) |
|
|
|
|
- pin/mux-handling (just overall concept due to project dependency) |
|
|
|
|
- multiple instances capability |
|
|
|
|
- slave functionality |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#include <linux/module.h> |
|
|
|
|
#include <linux/errno.h> |
|
|
|
@ -42,24 +44,23 @@ |
|
|
|
|
#include <linux/delay.h> |
|
|
|
|
#include <linux/spinlock.h> |
|
|
|
|
#include <linux/slab.h> |
|
|
|
|
|
|
|
|
|
#include <asm/system.h> |
|
|
|
|
#include <asm/io.h> |
|
|
|
|
#include <asm/irq.h> |
|
|
|
|
#include <asm/uaccess.h> |
|
|
|
|
#include <asm/bitops.h> |
|
|
|
|
#include <linux/io.h> |
|
|
|
|
#include <linux/irq.h> |
|
|
|
|
#include <linux/uaccess.h> |
|
|
|
|
#include <linux/bitops.h> |
|
|
|
|
|
|
|
|
|
#include <linux/types.h> |
|
|
|
|
#include <linux/kernel.h> |
|
|
|
|
#include <linux/version.h> |
|
|
|
|
|
|
|
|
|
#include <asm/system.h> |
|
|
|
|
#include <asm/ifxmips/ifxmips.h> |
|
|
|
|
#include <asm/ifxmips/ifxmips_irq.h> |
|
|
|
|
#include <asm/ifxmips/ifx_ssc_defines.h> |
|
|
|
|
#include <asm/ifxmips/ifx_ssc.h> |
|
|
|
|
|
|
|
|
|
/* allow the user to set the major device number */ |
|
|
|
|
static int maj = 0; |
|
|
|
|
static int maj; |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This is the per-channel data structure containing pointers, flags |
|
|
|
@ -75,22 +76,19 @@ static void tx_int (struct ifx_ssc_port *); |
|
|
|
|
extern unsigned int ifxmips_get_fpi_hz(void); |
|
|
|
|
extern void ifxmips_mask_and_ack_irq(unsigned int irq_nr); |
|
|
|
|
|
|
|
|
|
static inline unsigned int |
|
|
|
|
ifx_ssc_get_kernel_clk (struct ifx_ssc_port *info) |
|
|
|
|
static inline unsigned int ifx_ssc_get_kernel_clk(struct ifx_ssc_port *info) |
|
|
|
|
{ |
|
|
|
|
unsigned int rmc; |
|
|
|
|
|
|
|
|
|
rmc = (ifxmips_r32(IFXMIPS_SSC_CLC) & IFX_CLC_RUN_DIVIDER_MASK) >> IFX_CLC_RUN_DIVIDER_OFFSET; |
|
|
|
|
if (rmc == 0) |
|
|
|
|
{ |
|
|
|
|
if (rmc == 0) { |
|
|
|
|
printk("ifx_ssc_get_kernel_clk rmc==0 \n"); |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
return ifxmips_get_fpi_hz() / rmc; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inline static void |
|
|
|
|
rx_int (struct ifx_ssc_port *info) |
|
|
|
|
static inline void rx_int(struct ifx_ssc_port *info) |
|
|
|
|
{ |
|
|
|
|
int fifo_fill_lev, bytes_in_buf, i; |
|
|
|
|
unsigned long tmp_val; |
|
|
|
@ -99,7 +97,7 @@ rx_int (struct ifx_ssc_port *info) |
|
|
|
|
/* number of words waiting in the RX FIFO */ |
|
|
|
|
fifo_fill_lev = (ifxmips_r32(IFXMIPS_SSC_FSTAT) & IFX_SSC_FSTAT_RECEIVED_WORDS_MASK) >> IFX_SSC_FSTAT_RECEIVED_WORDS_OFFSET; |
|
|
|
|
bytes_in_buf = info->rxbuf_end - info->rxbuf_ptr; |
|
|
|
|
// transfer with 32 bits per entry
|
|
|
|
|
/* transfer with 32 bits per entry */ |
|
|
|
|
while ((bytes_in_buf >= 4) && (fifo_fill_lev > 0)) { |
|
|
|
|
tmp_ptr = (unsigned long *)info->rxbuf_ptr; |
|
|
|
|
*tmp_ptr = ifxmips_r32(IFXMIPS_SSC_RB); |
|
|
|
@ -109,7 +107,7 @@ rx_int (struct ifx_ssc_port *info) |
|
|
|
|
bytes_in_buf -= 4; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// now do the rest as mentioned in STATE.RXBV
|
|
|
|
|
/* now do the rest as mentioned in STATE.RXBV */ |
|
|
|
|
while ((bytes_in_buf > 0) && (fifo_fill_lev > 0)) { |
|
|
|
|
rx_valid_cnt = (ifxmips_r32(IFXMIPS_SSC_STATE) & IFX_SSC_STATE_RX_BYTE_VALID_MASK) >> IFX_SSC_STATE_RX_BYTE_VALID_OFFSET; |
|
|
|
|
if (rx_valid_cnt == 0) |
|
|
|
@ -120,8 +118,7 @@ rx_int (struct ifx_ssc_port *info) |
|
|
|
|
|
|
|
|
|
tmp_val = ifxmips_r32(IFXMIPS_SSC_RB); |
|
|
|
|
|
|
|
|
|
for (i = 0; i < rx_valid_cnt; i++) |
|
|
|
|
{ |
|
|
|
|
for (i = 0; i < rx_valid_cnt; i++) { |
|
|
|
|
*info->rxbuf_ptr = (tmp_val >> (8 * (rx_valid_cnt - i - 1))) & 0xff; |
|
|
|
|
bytes_in_buf--; |
|
|
|
|
info->rxbuf_ptr++; |
|
|
|
@ -129,13 +126,11 @@ rx_int (struct ifx_ssc_port *info) |
|
|
|
|
info->stats.rxBytes += rx_valid_cnt; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// check if transfer is complete
|
|
|
|
|
if (info->rxbuf_ptr >= info->rxbuf_end) |
|
|
|
|
{ |
|
|
|
|
/* check if transfer is complete */ |
|
|
|
|
if (info->rxbuf_ptr >= info->rxbuf_end) { |
|
|
|
|
disable_irq(IFXMIPS_SSC_RIR); |
|
|
|
|
wake_up_interruptible(&info->rwait); |
|
|
|
|
} else if ((info->opts.modeRxTx == IFX_SSC_MODE_RX) && (ifxmips_r32(IFXMIPS_SSC_RXCNT) == 0)) |
|
|
|
|
{ |
|
|
|
|
} else if ((info->opts.modeRxTx == IFX_SSC_MODE_RX) && (ifxmips_r32(IFXMIPS_SSC_RXCNT) == 0)) { |
|
|
|
|
if (info->rxbuf_end - info->rxbuf_ptr < IFX_SSC_RXREQ_BLOCK_SIZE) |
|
|
|
|
ifxmips_w32((info->rxbuf_end - info->rxbuf_ptr) << IFX_SSC_RXREQ_RXCOUNT_OFFSET, IFXMIPS_SSC_RXREQ); |
|
|
|
|
else |
|
|
|
@ -143,8 +138,7 @@ rx_int (struct ifx_ssc_port *info) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inline static void |
|
|
|
|
tx_int (struct ifx_ssc_port *info) |
|
|
|
|
static inline void tx_int(struct ifx_ssc_port *info) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
int fifo_space, fill, i; |
|
|
|
@ -159,9 +153,8 @@ tx_int (struct ifx_ssc_port *info) |
|
|
|
|
if (fill > fifo_space * 4) |
|
|
|
|
fill = fifo_space * 4; |
|
|
|
|
|
|
|
|
|
for (i = 0; i < fill / 4; i++) |
|
|
|
|
{ |
|
|
|
|
// at first 32 bit access
|
|
|
|
|
for (i = 0; i < fill / 4; i++) { |
|
|
|
|
/* at first 32 bit access */ |
|
|
|
|
ifxmips_w32(*(UINT32 *)info->txbuf_ptr, IFXMIPS_SSC_TB); |
|
|
|
|
info->txbuf_ptr += 4; |
|
|
|
|
} |
|
|
|
@ -169,9 +162,8 @@ tx_int (struct ifx_ssc_port *info) |
|
|
|
|
fifo_space -= fill / 4; |
|
|
|
|
info->stats.txBytes += fill & ~0x3; |
|
|
|
|
fill &= 0x3; |
|
|
|
|
if ((fifo_space > 0) & (fill > 1)) |
|
|
|
|
{ |
|
|
|
|
// trailing 16 bit access
|
|
|
|
|
if ((fifo_space > 0) & (fill > 1)) { |
|
|
|
|
/* trailing 16 bit access */ |
|
|
|
|
WRITE_PERIPHERAL_REGISTER_16(*(UINT16 *)info->txbuf_ptr, info->mapbase + IFX_SSC_TB); |
|
|
|
|
info->txbuf_ptr += 2; |
|
|
|
|
info->stats.txBytes += 2; |
|
|
|
@ -179,17 +171,15 @@ tx_int (struct ifx_ssc_port *info) |
|
|
|
|
fill -= 2; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ((fifo_space > 0) & (fill > 0)) |
|
|
|
|
{ |
|
|
|
|
// trailing 8 bit access
|
|
|
|
|
if ((fifo_space > 0) & (fill > 0)) { |
|
|
|
|
/* trailing 8 bit access */ |
|
|
|
|
WRITE_PERIPHERAL_REGISTER_8(*(UINT8 *)info->txbuf_ptr, info->mapbase + IFX_SSC_TB); |
|
|
|
|
info->txbuf_ptr++; |
|
|
|
|
info->stats.txBytes++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// check if transmission complete
|
|
|
|
|
if (info->txbuf_ptr >= info->txbuf_end) |
|
|
|
|
{ |
|
|
|
|
/* check if transmission complete */ |
|
|
|
|
if (info->txbuf_ptr >= info->txbuf_end) { |
|
|
|
|
disable_irq(IFXMIPS_SSC_TIR); |
|
|
|
|
kfree(info->txbuf); |
|
|
|
|
info->txbuf = NULL; |
|
|
|
@ -197,8 +187,7 @@ tx_int (struct ifx_ssc_port *info) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
irqreturn_t |
|
|
|
|
ifx_ssc_rx_int (int irq, void *dev_id) |
|
|
|
|
irqreturn_t ifx_ssc_rx_int(int irq, void *dev_id) |
|
|
|
|
{ |
|
|
|
|
struct ifx_ssc_port *info = (struct ifx_ssc_port *)dev_id; |
|
|
|
|
rx_int(info); |
|
|
|
@ -206,8 +195,7 @@ ifx_ssc_rx_int (int irq, void *dev_id) |
|
|
|
|
return IRQ_HANDLED; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
irqreturn_t |
|
|
|
|
ifx_ssc_tx_int (int irq, void *dev_id) |
|
|
|
|
irqreturn_t ifx_ssc_tx_int(int irq, void *dev_id) |
|
|
|
|
{ |
|
|
|
|
struct ifx_ssc_port *info = (struct ifx_ssc_port *)dev_id; |
|
|
|
|
tx_int(info); |
|
|
|
@ -215,8 +203,7 @@ ifx_ssc_tx_int (int irq, void *dev_id) |
|
|
|
|
return IRQ_HANDLED; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
irqreturn_t |
|
|
|
|
ifx_ssc_err_int (int irq, void *dev_id) |
|
|
|
|
irqreturn_t ifx_ssc_err_int(int irq, void *dev_id) |
|
|
|
|
{ |
|
|
|
|
struct ifx_ssc_port *info = (struct ifx_ssc_port *)dev_id; |
|
|
|
|
unsigned int state; |
|
|
|
@ -259,8 +246,7 @@ ifx_ssc_err_int (int irq, void *dev_id) |
|
|
|
|
return IRQ_HANDLED; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
ifx_ssc_abort (struct ifx_ssc_port *info) |
|
|
|
|
static void ifx_ssc_abort(struct ifx_ssc_port *info) |
|
|
|
|
{ |
|
|
|
|
unsigned long flags; |
|
|
|
|
bool enabled; |
|
|
|
@ -273,35 +259,35 @@ ifx_ssc_abort (struct ifx_ssc_port *info) |
|
|
|
|
|
|
|
|
|
local_irq_restore(flags); |
|
|
|
|
|
|
|
|
|
// disable SSC (also aborts a receive request!)
|
|
|
|
|
// ### TO DO: Perhaps it's better to abort after the receiption of a
|
|
|
|
|
// complete word. The disable cuts the transmission immediatly and
|
|
|
|
|
// releases the chip selects. This could result in unpredictable
|
|
|
|
|
// behavior of connected external devices!
|
|
|
|
|
/* disable SSC(also aborts a receive request!) */ |
|
|
|
|
/* ### TO DO: Perhaps it's better to abort after the receiption of a
|
|
|
|
|
complete word. The disable cuts the transmission immediatly and |
|
|
|
|
releases the chip selects. This could result in unpredictable |
|
|
|
|
behavior of connected external devices! |
|
|
|
|
*/ |
|
|
|
|
enabled = (ifxmips_r32(IFXMIPS_SSC_STATE) & IFX_SSC_STATE_IS_ENABLED) != 0; |
|
|
|
|
ifxmips_w32(IFX_SSC_WHBSTATE_CLR_ENABLE, IFXMIPS_SSC_WHBSTATE); |
|
|
|
|
|
|
|
|
|
// flush fifos
|
|
|
|
|
/* flush fifos */ |
|
|
|
|
ifxmips_w32(IFX_SSC_XFCON_FIFO_FLUSH, IFXMIPS_SSC_TXFCON); |
|
|
|
|
ifxmips_w32(IFX_SSC_XFCON_FIFO_FLUSH, IFXMIPS_SSC_RXFCON); |
|
|
|
|
|
|
|
|
|
// free txbuf
|
|
|
|
|
if (info->txbuf != NULL) |
|
|
|
|
{ |
|
|
|
|
/* free txbuf */ |
|
|
|
|
if (info->txbuf != NULL) { |
|
|
|
|
kfree(info->txbuf); |
|
|
|
|
info->txbuf = NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// wakeup read process
|
|
|
|
|
/* wakeup read process */ |
|
|
|
|
if (info->rxbuf != NULL) |
|
|
|
|
wake_up_interruptible(&info->rwait); |
|
|
|
|
|
|
|
|
|
// clear pending int's
|
|
|
|
|
/* clear pending int's */ |
|
|
|
|
ifxmips_mask_and_ack_irq(IFXMIPS_SSC_RIR); |
|
|
|
|
ifxmips_mask_and_ack_irq(IFXMIPS_SSC_TIR); |
|
|
|
|
ifxmips_mask_and_ack_irq(IFXMIPS_SSC_EIR); |
|
|
|
|
|
|
|
|
|
// clear error flags
|
|
|
|
|
/* clear error flags */ |
|
|
|
|
ifxmips_w32(IFX_SSC_WHBSTATE_CLR_ALL_ERROR, IFXMIPS_SSC_WHBSTATE); |
|
|
|
|
|
|
|
|
|
if (enabled) |
|
|
|
@ -313,8 +299,7 @@ ifx_ssc_abort (struct ifx_ssc_port *info) |
|
|
|
|
* This routine is called whenever a port is opened. It enforces |
|
|
|
|
* exclusive opening of a port and enables interrupts, etc. |
|
|
|
|
*/ |
|
|
|
|
int |
|
|
|
|
ifx_ssc_open (struct inode *inode, struct file *filp) |
|
|
|
|
int ifx_ssc_open(struct inode *inode, struct file *filp) |
|
|
|
|
{ |
|
|
|
|
struct ifx_ssc_port *info; |
|
|
|
|
int line; |
|
|
|
@ -323,9 +308,8 @@ ifx_ssc_open (struct inode *inode, struct file *filp) |
|
|
|
|
if ((inode == (struct inode *)0) || (inode == (struct inode *)1)) { |
|
|
|
|
from_kernel = 1; |
|
|
|
|
line = (int) inode; |
|
|
|
|
} else { |
|
|
|
|
} else |
|
|
|
|
line = MINOR(filp->f_dentry->d_inode->i_rdev); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* don't open more minor devices than we can support */ |
|
|
|
|
if (line < 0 || line >= PORT_CNT) |
|
|
|
@ -353,7 +337,7 @@ ifx_ssc_open (struct inode *inode, struct file *filp) |
|
|
|
|
/* clear all error bits */ |
|
|
|
|
ifxmips_w32(IFX_SSC_WHBSTATE_CLR_ALL_ERROR, IFXMIPS_SSC_WHBSTATE); |
|
|
|
|
|
|
|
|
|
// clear pending interrupts
|
|
|
|
|
/* clear pending interrupts */ |
|
|
|
|
ifxmips_mask_and_ack_irq(IFXMIPS_SSC_RIR); |
|
|
|
|
ifxmips_mask_and_ack_irq(IFXMIPS_SSC_TIR); |
|
|
|
|
ifxmips_mask_and_ack_irq(IFXMIPS_SSC_EIR); |
|
|
|
@ -364,8 +348,7 @@ ifx_ssc_open (struct inode *inode, struct file *filp) |
|
|
|
|
} |
|
|
|
|
EXPORT_SYMBOL(ifx_ssc_open); |
|
|
|
|
|
|
|
|
|
int |
|
|
|
|
ifx_ssc_close (struct inode *inode, struct file *filp) |
|
|
|
|
int ifx_ssc_close(struct inode *inode, struct file *filp) |
|
|
|
|
{ |
|
|
|
|
struct ifx_ssc_port *info; |
|
|
|
|
int idx; |
|
|
|
@ -392,8 +375,8 @@ ifx_ssc_close (struct inode *inode, struct file *filp) |
|
|
|
|
} |
|
|
|
|
EXPORT_SYMBOL(ifx_ssc_close); |
|
|
|
|
|
|
|
|
|
static ssize_t |
|
|
|
|
ifx_ssc_read_helper_poll (struct ifx_ssc_port *info, char *buf, size_t len, int from_kernel) |
|
|
|
|
static ssize_t ifx_ssc_read_helper_poll(struct ifx_ssc_port *info, char *buf, |
|
|
|
|
size_t len, int from_kernel) |
|
|
|
|
{ |
|
|
|
|
ssize_t ret_val; |
|
|
|
|
unsigned long flags; |
|
|
|
@ -406,8 +389,7 @@ ifx_ssc_read_helper_poll (struct ifx_ssc_port *info, char *buf, size_t len, int |
|
|
|
|
local_irq_restore(flags); |
|
|
|
|
/* Vinetic driver always works in IFX_SSC_MODE_RXTX */ |
|
|
|
|
/* TXRX in poll mode */ |
|
|
|
|
while (info->rxbuf_ptr < info->rxbuf_end) |
|
|
|
|
{ |
|
|
|
|
while (info->rxbuf_ptr < info->rxbuf_end) { |
|
|
|
|
if (info->txbuf_ptr < info->txbuf_end) |
|
|
|
|
tx_int(info); |
|
|
|
|
|
|
|
|
@ -419,8 +401,8 @@ ifx_ssc_read_helper_poll (struct ifx_ssc_port *info, char *buf, size_t len, int |
|
|
|
|
return ret_val; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static ssize_t |
|
|
|
|
ifx_ssc_read_helper (struct ifx_ssc_port *info, char *buf, size_t len, int from_kernel) |
|
|
|
|
static ssize_t ifx_ssc_read_helper(struct ifx_ssc_port *info, char *buf, |
|
|
|
|
size_t len, int from_kernel) |
|
|
|
|
{ |
|
|
|
|
ssize_t ret_val; |
|
|
|
|
unsigned long flags; |
|
|
|
@ -433,10 +415,8 @@ ifx_ssc_read_helper (struct ifx_ssc_port *info, char *buf, size_t len, int from_ |
|
|
|
|
info->rxbuf_ptr = info->rxbuf; |
|
|
|
|
info->rxbuf_end = info->rxbuf + len; |
|
|
|
|
|
|
|
|
|
if (info->opts.modeRxTx == IFX_SSC_MODE_RXTX) |
|
|
|
|
{ |
|
|
|
|
if ((info->txbuf == NULL) || (info->txbuf != info->txbuf_ptr) || (info->txbuf_end != len + info->txbuf)) |
|
|
|
|
{ |
|
|
|
|
if (info->opts.modeRxTx == IFX_SSC_MODE_RXTX) { |
|
|
|
|
if ((info->txbuf == NULL) || (info->txbuf != info->txbuf_ptr) || (info->txbuf_end != len + info->txbuf)) { |
|
|
|
|
local_irq_restore(flags); |
|
|
|
|
printk("IFX SSC - %s: write must be called before calling " "read in combined RX/TX!\n", __func__); |
|
|
|
|
return -EFAULT; |
|
|
|
@ -470,8 +450,7 @@ ifx_ssc_read_helper (struct ifx_ssc_port *info, char *buf, size_t len, int from_ |
|
|
|
|
|
|
|
|
|
local_irq_restore(flags); |
|
|
|
|
|
|
|
|
|
if (signal_pending (current)) |
|
|
|
|
{ |
|
|
|
|
if (signal_pending(current)) { |
|
|
|
|
ret_val = -ERESTARTSYS; |
|
|
|
|
goto out; |
|
|
|
|
} |
|
|
|
@ -485,11 +464,10 @@ out: |
|
|
|
|
current->state = TASK_RUNNING; |
|
|
|
|
__remove_wait_queue(&info->rwait, &wait); |
|
|
|
|
|
|
|
|
|
return (ret_val); |
|
|
|
|
return ret_val; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static ssize_t |
|
|
|
|
ifx_ssc_write_helper (struct ifx_ssc_port *info, const char *buf, |
|
|
|
|
static ssize_t ifx_ssc_write_helper(struct ifx_ssc_port *info, const char *buf, |
|
|
|
|
size_t len, int from_kernel) |
|
|
|
|
{ |
|
|
|
|
if (info->opts.modeRxTx == IFX_SSC_MODE_RX) |
|
|
|
@ -497,20 +475,16 @@ ifx_ssc_write_helper (struct ifx_ssc_port *info, const char *buf, |
|
|
|
|
|
|
|
|
|
info->txbuf_ptr = info->txbuf; |
|
|
|
|
info->txbuf_end = len + info->txbuf; |
|
|
|
|
if (info->opts.modeRxTx == IFX_SSC_MODE_TX) |
|
|
|
|
{ |
|
|
|
|
if (info->opts.modeRxTx == IFX_SSC_MODE_TX) { |
|
|
|
|
tx_int(info); |
|
|
|
|
if (info->txbuf_ptr < info->txbuf_end) |
|
|
|
|
{ |
|
|
|
|
enable_irq(IFXMIPS_SSC_TIR); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return len; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ssize_t |
|
|
|
|
ifx_ssc_kread (int port, char *kbuf, size_t len) |
|
|
|
|
ssize_t ifx_ssc_kread(int port, char *kbuf, size_t len) |
|
|
|
|
{ |
|
|
|
|
struct ifx_ssc_port *info; |
|
|
|
|
ssize_t ret_val; |
|
|
|
@ -523,15 +497,13 @@ ifx_ssc_kread (int port, char *kbuf, size_t len) |
|
|
|
|
|
|
|
|
|
info = &isp[port]; |
|
|
|
|
|
|
|
|
|
if (info->rxbuf != NULL) |
|
|
|
|
{ |
|
|
|
|
if (info->rxbuf != NULL) { |
|
|
|
|
printk("SSC device busy\n"); |
|
|
|
|
return -EBUSY; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
info->rxbuf = kbuf; |
|
|
|
|
if (info->rxbuf == NULL) |
|
|
|
|
{ |
|
|
|
|
if (info->rxbuf == NULL) { |
|
|
|
|
printk("SSC device error\n"); |
|
|
|
|
return -EINVAL; |
|
|
|
|
} |
|
|
|
@ -545,8 +517,7 @@ ifx_ssc_kread (int port, char *kbuf, size_t len) |
|
|
|
|
} |
|
|
|
|
EXPORT_SYMBOL(ifx_ssc_kread); |
|
|
|
|
|
|
|
|
|
ssize_t |
|
|
|
|
ifx_ssc_kwrite (int port, const char *kbuf, size_t len) |
|
|
|
|
ssize_t ifx_ssc_kwrite(int port, const char *kbuf, size_t len) |
|
|
|
|
{ |
|
|
|
|
struct ifx_ssc_port *info; |
|
|
|
|
ssize_t ret_val; |
|
|
|
@ -559,7 +530,7 @@ ifx_ssc_kwrite (int port, const char *kbuf, size_t len) |
|
|
|
|
|
|
|
|
|
info = &isp[port]; |
|
|
|
|
|
|
|
|
|
// check if transmission in progress
|
|
|
|
|
/* check if transmission in progress */ |
|
|
|
|
if (info->txbuf != NULL) |
|
|
|
|
return -EBUSY; |
|
|
|
|
|
|
|
|
@ -574,8 +545,7 @@ ifx_ssc_kwrite (int port, const char *kbuf, size_t len) |
|
|
|
|
} |
|
|
|
|
EXPORT_SYMBOL(ifx_ssc_kwrite); |
|
|
|
|
|
|
|
|
|
static ssize_t |
|
|
|
|
ifx_ssc_read (struct file *filp, char *ubuf, size_t len, loff_t * off) |
|
|
|
|
static ssize_t ifx_ssc_read(struct file *filp, char *ubuf, size_t len, loff_t *off) |
|
|
|
|
{ |
|
|
|
|
ssize_t ret_val; |
|
|
|
|
int idx; |
|
|
|
@ -600,18 +570,17 @@ ifx_ssc_read (struct file *filp, char *ubuf, size_t len, loff_t * off) |
|
|
|
|
kfree(info->rxbuf); |
|
|
|
|
info->rxbuf = NULL; |
|
|
|
|
|
|
|
|
|
return (ret_val); |
|
|
|
|
return ret_val; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static ssize_t |
|
|
|
|
ifx_ssc_write (struct file *filp, const char *ubuf, size_t len, loff_t * off) |
|
|
|
|
static ssize_t ifx_ssc_write(struct file *filp, const char *ubuf, size_t len, loff_t *off) |
|
|
|
|
{ |
|
|
|
|
int idx; |
|
|
|
|
struct ifx_ssc_port *info; |
|
|
|
|
int ret_val; |
|
|
|
|
|
|
|
|
|
if (len == 0) |
|
|
|
|
return (0); |
|
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
idx = MINOR(filp->f_dentry->d_inode->i_rdev); |
|
|
|
|
info = &isp[idx]; |
|
|
|
@ -629,17 +598,15 @@ ifx_ssc_write (struct file *filp, const char *ubuf, size_t len, loff_t * off) |
|
|
|
|
else |
|
|
|
|
ret_val = -EFAULT; |
|
|
|
|
|
|
|
|
|
if (ret_val < 0) |
|
|
|
|
{ |
|
|
|
|
if (ret_val < 0) { |
|
|
|
|
kfree(info->txbuf); |
|
|
|
|
info->txbuf = NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return (ret_val); |
|
|
|
|
return ret_val; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static struct ifx_ssc_frm_status * |
|
|
|
|
ifx_ssc_frm_status_get (struct ifx_ssc_port *info) |
|
|
|
|
static struct ifx_ssc_frm_status *ifx_ssc_frm_status_get(struct ifx_ssc_port *info) |
|
|
|
|
{ |
|
|
|
|
unsigned long tmp; |
|
|
|
|
|
|
|
|
@ -655,9 +622,7 @@ ifx_ssc_frm_status_get (struct ifx_ssc_port *info) |
|
|
|
|
return &info->frm_status; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static struct ifx_ssc_frm_opts * |
|
|
|
|
ifx_ssc_frm_control_get (struct ifx_ssc_port *info) |
|
|
|
|
static struct ifx_ssc_frm_opts *ifx_ssc_frm_control_get(struct ifx_ssc_port *info) |
|
|
|
|
{ |
|
|
|
|
unsigned long tmp; |
|
|
|
|
|
|
|
|
@ -672,8 +637,7 @@ ifx_ssc_frm_control_get (struct ifx_ssc_port *info) |
|
|
|
|
return &info->frm_opts; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int |
|
|
|
|
ifx_ssc_frm_control_set (struct ifx_ssc_port *info) |
|
|
|
|
static int ifx_ssc_frm_control_set(struct ifx_ssc_port *info) |
|
|
|
|
{ |
|
|
|
|
unsigned long tmp; |
|
|
|
|
|
|
|
|
@ -685,12 +649,12 @@ ifx_ssc_frm_control_set (struct ifx_ssc_port *info) |
|
|
|
|
|| (info->frm_opts.IdleClock & ~(IFX_SSC_SFCON_PAUSE_CLOCK_MASK >> IFX_SSC_SFCON_PAUSE_CLOCK_OFFSET))) |
|
|
|
|
return -EINVAL; |
|
|
|
|
|
|
|
|
|
// read interrupt bits (they're not changed here)
|
|
|
|
|
/* read interrupt bits(they're not changed here) */ |
|
|
|
|
tmp = ifxmips_r32(IFXMIPS_SSC_SFCON) & |
|
|
|
|
(IFX_SSC_SFCON_FIR_ENABLE_BEFORE_PAUSE | IFX_SSC_SFCON_FIR_ENABLE_AFTER_PAUSE); |
|
|
|
|
|
|
|
|
|
// set all values with respect to it's bit position (for data and pause
|
|
|
|
|
// length set N-1)
|
|
|
|
|
/* set all values with respect to it's bit position(for data and pause
|
|
|
|
|
length set N-1) */ |
|
|
|
|
tmp = (info->frm_opts.DataLength - 1) << IFX_SSC_SFCON_DATA_LENGTH_OFFSET; |
|
|
|
|
tmp |= (info->frm_opts.PauseLength - 1) << IFX_SSC_SFCON_PAUSE_LENGTH_OFFSET; |
|
|
|
|
tmp |= info->frm_opts.IdleData << IFX_SSC_SFCON_PAUSE_DATA_OFFSET; |
|
|
|
@ -703,8 +667,7 @@ ifx_ssc_frm_control_set (struct ifx_ssc_port *info) |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int |
|
|
|
|
ifx_ssc_rxtx_mode_set (struct ifx_ssc_port *info, unsigned int val) |
|
|
|
|
static int ifx_ssc_rxtx_mode_set(struct ifx_ssc_port *info, unsigned int val) |
|
|
|
|
{ |
|
|
|
|
unsigned long tmp; |
|
|
|
|
|
|
|
|
@ -722,8 +685,7 @@ ifx_ssc_rxtx_mode_set (struct ifx_ssc_port *info, unsigned int val) |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int |
|
|
|
|
ifx_ssc_sethwopts (struct ifx_ssc_port *info) |
|
|
|
|
static int ifx_ssc_sethwopts(struct ifx_ssc_port *info) |
|
|
|
|
{ |
|
|
|
|
unsigned long flags, bits; |
|
|
|
|
struct ifx_ssc_hwopts *opts = &info->opts; |
|
|
|
@ -754,8 +716,7 @@ ifx_ssc_sethwopts (struct ifx_ssc_port *info) |
|
|
|
|
if (opts->clockPolarity) |
|
|
|
|
bits |= IFX_SSC_CON_CLOCK_FALL; |
|
|
|
|
|
|
|
|
|
switch (opts->modeRxTx) |
|
|
|
|
{ |
|
|
|
|
switch (opts->modeRxTx) { |
|
|
|
|
case IFX_SSC_MODE_TX: |
|
|
|
|
bits |= IFX_SSC_CON_RX_OFF; |
|
|
|
|
break; |
|
|
|
@ -772,16 +733,16 @@ ifx_ssc_sethwopts (struct ifx_ssc_port *info) |
|
|
|
|
|
|
|
|
|
ifxmips_w32(info->opts.gpoCs << IFX_SSC_WHBGPOSTAT_SETOUT0_POS, IFXMIPS_SSC_WHBGPOSTAT); |
|
|
|
|
|
|
|
|
|
//master mode
|
|
|
|
|
/* master mode */ |
|
|
|
|
if (opts->masterSelect) |
|
|
|
|
ifxmips_w32(IFX_SSC_WHBSTATE_SET_MASTER_SELECT, IFXMIPS_SSC_WHBSTATE); |
|
|
|
|
else |
|
|
|
|
ifxmips_w32(IFX_SSC_WHBSTATE_CLR_MASTER_SELECT, IFXMIPS_SSC_WHBSTATE); |
|
|
|
|
|
|
|
|
|
// init serial framing
|
|
|
|
|
/* init serial framing */ |
|
|
|
|
ifxmips_w32(0, IFXMIPS_SSC_SFCON); |
|
|
|
|
/* set up the port pins */ |
|
|
|
|
//check for general requirements to switch (external) pad/pin characteristics
|
|
|
|
|
/* check for general requirements to switch(external) pad/pin characteristics */ |
|
|
|
|
/* TODO: P0.9 SPI_CS4, P0.10 SPI_CS5, P 0.11 SPI_CS6, because of ASC0 */ |
|
|
|
|
/* p0.15 SPI_CS1(EEPROM), P0.13 SPI_CS3, */ |
|
|
|
|
/* Set p0.15 to alternative 01, others to 00(In/OUT) */ |
|
|
|
@ -805,8 +766,7 @@ ifx_ssc_sethwopts (struct ifx_ssc_port *info) |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int |
|
|
|
|
ifx_ssc_set_baud (struct ifx_ssc_port *info, unsigned int baud) |
|
|
|
|
static int ifx_ssc_set_baud(struct ifx_ssc_port *info, unsigned int baud) |
|
|
|
|
{ |
|
|
|
|
unsigned int ifx_ssc_clock; |
|
|
|
|
unsigned int br; |
|
|
|
@ -815,8 +775,7 @@ ifx_ssc_set_baud (struct ifx_ssc_port *info, unsigned int baud) |
|
|
|
|
int retval = 0; |
|
|
|
|
|
|
|
|
|
ifx_ssc_clock = ifx_ssc_get_kernel_clk(info); |
|
|
|
|
if (ifx_ssc_clock == 0) |
|
|
|
|
{ |
|
|
|
|
if (ifx_ssc_clock == 0) { |
|
|
|
|
retval = -EINVAL; |
|
|
|
|
goto out; |
|
|
|
|
} |
|
|
|
@ -847,8 +806,7 @@ out: |
|
|
|
|
return retval; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int |
|
|
|
|
ifx_ssc_hwinit (struct ifx_ssc_port *info) |
|
|
|
|
static int ifx_ssc_hwinit(struct ifx_ssc_port *info) |
|
|
|
|
{ |
|
|
|
|
unsigned long flags; |
|
|
|
|
bool enabled; |
|
|
|
@ -856,14 +814,12 @@ ifx_ssc_hwinit (struct ifx_ssc_port *info) |
|
|
|
|
enabled = (ifxmips_r32(IFXMIPS_SSC_STATE) & IFX_SSC_STATE_IS_ENABLED); |
|
|
|
|
ifxmips_w32(IFX_SSC_WHBSTATE_CLR_ENABLE, IFXMIPS_SSC_WHBSTATE); |
|
|
|
|
|
|
|
|
|
if (ifx_ssc_sethwopts (info) < 0) |
|
|
|
|
{ |
|
|
|
|
if (ifx_ssc_sethwopts(info) < 0) { |
|
|
|
|
printk("%s: setting the hardware options failed\n", __func__); |
|
|
|
|
return -EINVAL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (ifx_ssc_set_baud (info, info->baud) < 0) |
|
|
|
|
{ |
|
|
|
|
if (ifx_ssc_set_baud(info, info->baud) < 0) { |
|
|
|
|
printk("%s: setting the baud rate failed\n", __func__); |
|
|
|
|
return -EINVAL; |
|
|
|
|
} |
|
|
|
@ -883,8 +839,8 @@ ifx_ssc_hwinit (struct ifx_ssc_port *info) |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int |
|
|
|
|
ifx_ssc_ioctl (struct inode *inode, struct file *filp, unsigned int cmd, unsigned long data) |
|
|
|
|
int ifx_ssc_ioctl(struct inode *inode, struct file *filp, |
|
|
|
|
unsigned int cmd, unsigned long data) |
|
|
|
|
{ |
|
|
|
|
struct ifx_ssc_port *info; |
|
|
|
|
int line, ret_val = 0; |
|
|
|
@ -892,21 +848,18 @@ ifx_ssc_ioctl (struct inode *inode, struct file *filp, unsigned int cmd, unsigne |
|
|
|
|
unsigned long tmp; |
|
|
|
|
int from_kernel = 0; |
|
|
|
|
|
|
|
|
|
if ((inode == (struct inode *) 0) || (inode == (struct inode *) 1)) |
|
|
|
|
{ |
|
|
|
|
if ((inode == (struct inode *)0) || (inode == (struct inode *)1)) { |
|
|
|
|
from_kernel = 1; |
|
|
|
|
line = (int) inode; |
|
|
|
|
} else { |
|
|
|
|
} else |
|
|
|
|
line = MINOR(filp->f_dentry->d_inode->i_rdev); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (line < 0 || line >= PORT_CNT) |
|
|
|
|
return -ENXIO; |
|
|
|
|
|
|
|
|
|
info = &isp[line]; |
|
|
|
|
|
|
|
|
|
switch (cmd) |
|
|
|
|
{ |
|
|
|
|
switch (cmd) { |
|
|
|
|
case IFX_SSC_STATS_READ: |
|
|
|
|
/* data must be a pointer to a struct ifx_ssc_statistics */ |
|
|
|
|
if (from_kernel) |
|
|
|
@ -1003,10 +956,9 @@ ifx_ssc_ioctl (struct inode *inode, struct file *filp, unsigned int cmd, unsigne |
|
|
|
|
} |
|
|
|
|
if (tmp > IFX_SSC_MAX_GPO_OUT) |
|
|
|
|
ret_val = -EINVAL; |
|
|
|
|
else { |
|
|
|
|
else |
|
|
|
|
ifxmips_w32(1 << (tmp + IFX_SSC_WHBGPOSTAT_CLROUT0_POS), |
|
|
|
|
IFXMIPS_SSC_WHBGPOSTAT); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case IFX_SSC_GPO_OUT_GET: |
|
|
|
|
tmp = ifxmips_r32(IFXMIPS_SSC_GPOSTAT); |
|
|
|
@ -1066,9 +1018,8 @@ ifx_ssc_ioctl (struct inode *inode, struct file *filp, unsigned int cmd, unsigne |
|
|
|
|
ret_val = -EFAULT; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
if (ifx_ssc_hwinit (info) < 0) { |
|
|
|
|
if (ifx_ssc_hwinit(info) < 0) |
|
|
|
|
ret_val = -EIO; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case IFX_SSC_HWOPTS_GET: |
|
|
|
|
/* data must be a pointer to a struct ifx_ssc_hwopts */ |
|
|
|
@ -1097,8 +1048,7 @@ static struct file_operations ifx_ssc_fops = { |
|
|
|
|
.release = ifx_ssc_close, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
int __init |
|
|
|
|
ifx_ssc_init (void) |
|
|
|
|
int __init ifx_ssc_init(void) |
|
|
|
|
{ |
|
|
|
|
struct ifx_ssc_port *info; |
|
|
|
|
int i, nbytes; |
|
|
|
@ -1107,26 +1057,24 @@ ifx_ssc_init (void) |
|
|
|
|
|
|
|
|
|
ret_val = -ENOMEM; |
|
|
|
|
nbytes = PORT_CNT * sizeof(struct ifx_ssc_port); |
|
|
|
|
isp = (struct ifx_ssc_port*)kmalloc(nbytes, GFP_KERNEL); |
|
|
|
|
isp = kmalloc(nbytes, GFP_KERNEL); |
|
|
|
|
|
|
|
|
|
if (isp == NULL) |
|
|
|
|
{ |
|
|
|
|
if (isp == NULL) { |
|
|
|
|
printk("%s: no memory for isp\n", __func__); |
|
|
|
|
return (ret_val); |
|
|
|
|
return ret_val; |
|
|
|
|
} |
|
|
|
|
memset(isp, 0, nbytes); |
|
|
|
|
|
|
|
|
|
ret_val = -ENXIO; |
|
|
|
|
if ((i = register_chrdev (maj, "ssc", &ifx_ssc_fops)) < 0) |
|
|
|
|
{ |
|
|
|
|
i = register_chrdev(maj, "ssc", &ifx_ssc_fops); |
|
|
|
|
if (i < 0) { |
|
|
|
|
printk("Unable to register major %d for the Infineon SSC\n", maj); |
|
|
|
|
if (maj == 0) |
|
|
|
|
{ |
|
|
|
|
if (maj == 0) { |
|
|
|
|
goto errout; |
|
|
|
|
} else { |
|
|
|
|
maj = 0; |
|
|
|
|
if ((i = register_chrdev (maj, "ssc", &ifx_ssc_fops)) < 0) |
|
|
|
|
{ |
|
|
|
|
i = register_chrdev(maj, "ssc", &ifx_ssc_fops); |
|
|
|
|
if (i < 0) { |
|
|
|
|
printk("Unable to register major %d for the Infineon SSC\n", maj); |
|
|
|
|
goto errout; |
|
|
|
|
} |
|
|
|
@ -1161,9 +1109,8 @@ ifx_ssc_init (void) |
|
|
|
|
info->rxbuf = NULL; |
|
|
|
|
info->txbuf = NULL; |
|
|
|
|
/* values specific to SSC1 */ |
|
|
|
|
if (i == 0) { |
|
|
|
|
if (i == 0) |
|
|
|
|
info->mapbase = IFXMIPS_SSC_BASE_ADDR; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ifxmips_w32(IFX_SSC_DEF_RMC << IFX_CLC_RUN_DIVIDER_OFFSET, IFXMIPS_SSC_CLC); |
|
|
|
|
|
|
|
|
@ -1171,45 +1118,43 @@ ifx_ssc_init (void) |
|
|
|
|
|
|
|
|
|
local_irq_save(flags); |
|
|
|
|
|
|
|
|
|
// init serial framing register
|
|
|
|
|
/* init serial framing register */ |
|
|
|
|
ifxmips_w32(IFX_SSC_DEF_SFCON, IFXMIPS_SSC_SFCON); |
|
|
|
|
|
|
|
|
|
ret_val = request_irq(IFXMIPS_SSC_TIR, ifx_ssc_tx_int, IRQF_DISABLED, "ifx_ssc_tx", info); |
|
|
|
|
if (ret_val) |
|
|
|
|
{ |
|
|
|
|
if (ret_val) { |
|
|
|
|
printk("%s: unable to get irq %d\n", __func__, IFXMIPS_SSC_TIR); |
|
|
|
|
local_irq_restore(flags); |
|
|
|
|
goto errout; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ret_val = request_irq(IFXMIPS_SSC_RIR, ifx_ssc_rx_int, IRQF_DISABLED, "ifx_ssc_rx", info); |
|
|
|
|
if (ret_val) |
|
|
|
|
{ |
|
|
|
|
if (ret_val) { |
|
|
|
|
printk("%s: unable to get irq %d\n", __func__, IFXMIPS_SSC_RIR); |
|
|
|
|
local_irq_restore(flags); |
|
|
|
|
goto irqerr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ret_val = request_irq(IFXMIPS_SSC_EIR, ifx_ssc_err_int, IRQF_DISABLED, "ifx_ssc_err", info); |
|
|
|
|
if (ret_val) |
|
|
|
|
{ |
|
|
|
|
if (ret_val) { |
|
|
|
|
printk("%s: unable to get irq %d\n", __func__, IFXMIPS_SSC_EIR); |
|
|
|
|
local_irq_restore(flags); |
|
|
|
|
goto irqerr; |
|
|
|
|
} |
|
|
|
|
ifxmips_w32(IFX_SSC_DEF_IRNEN, IFXMIPS_SSC_IRN); |
|
|
|
|
|
|
|
|
|
//enable_irq(IFXMIPS_SSC_TIR);
|
|
|
|
|
//enable_irq(IFXMIPS_SSC_RIR);
|
|
|
|
|
//enable_irq(IFXMIPS_SSC_EIR);
|
|
|
|
|
#if 0 |
|
|
|
|
enable_irq(IFXMIPS_SSC_TIR); |
|
|
|
|
enable_irq(IFXMIPS_SSC_RIR); |
|
|
|
|
enable_irq(IFXMIPS_SSC_EIR); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
local_irq_restore(flags); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (i = 0; i < PORT_CNT; i++) { |
|
|
|
|
info = &isp[i]; |
|
|
|
|
if (ifx_ssc_hwinit (info) < 0) |
|
|
|
|
{ |
|
|
|
|
if (ifx_ssc_hwinit(info) < 0) { |
|
|
|
|
printk("%s: hardware init failed for port %d\n", __func__, i); |
|
|
|
|
goto irqerr; |
|
|
|
|
} |
|
|
|
@ -1224,11 +1169,10 @@ irqerr: |
|
|
|
|
free_irq(IFXMIPS_SSC_EIR, &isp[0]); |
|
|
|
|
errout: |
|
|
|
|
kfree(isp); |
|
|
|
|
return (ret_val); |
|
|
|
|
return ret_val; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
ifx_ssc_cleanup_module (void) |
|
|
|
|
void __exit ifx_ssc_cleanup_module(void) |
|
|
|
|
{ |
|
|
|
|
int i; |
|
|
|
|
|
|
|
|
@ -1244,12 +1188,11 @@ ifx_ssc_cleanup_module (void) |
|
|
|
|
module_init(ifx_ssc_init); |
|
|
|
|
module_exit(ifx_ssc_cleanup_module); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline int |
|
|
|
|
ifx_ssc_cs_low (u32 pin) |
|
|
|
|
inline int ifx_ssc_cs_low(u32 pin) |
|
|
|
|
{ |
|
|
|
|
int ret = 0; |
|
|
|
|
if ((ret = ifx_ssc_ioctl ((struct inode *) 0, NULL, IFX_SSC_GPO_OUT_CLR, (unsigned long) &pin))) |
|
|
|
|
ret = ifx_ssc_ioctl((struct inode *)0, NULL, IFX_SSC_GPO_OUT_CLR, (unsigned long) &pin); |
|
|
|
|
if (ret) |
|
|
|
|
printk("clear CS %d fails\n", pin); |
|
|
|
|
wmb(); |
|
|
|
|
|
|
|
|
@ -1257,11 +1200,11 @@ ifx_ssc_cs_low (u32 pin) |
|
|
|
|
} |
|
|
|
|
EXPORT_SYMBOL(ifx_ssc_cs_low); |
|
|
|
|
|
|
|
|
|
inline int |
|
|
|
|
ifx_ssc_cs_high (u32 pin) |
|
|
|
|
inline int ifx_ssc_cs_high(u32 pin) |
|
|
|
|
{ |
|
|
|
|
int ret = 0; |
|
|
|
|
if ((ret = ifx_ssc_ioctl((struct inode *) 0, NULL, IFX_SSC_GPO_OUT_SET, (unsigned long) &pin))) |
|
|
|
|
ret = ifx_ssc_ioctl((struct inode *)0, NULL, IFX_SSC_GPO_OUT_SET, (unsigned long) &pin); |
|
|
|
|
if (ret) |
|
|
|
|
printk("set CS %d fails\n", pin); |
|
|
|
|
wmb(); |
|
|
|
|
|
|
|
|
@ -1269,8 +1212,7 @@ ifx_ssc_cs_high (u32 pin) |
|
|
|
|
} |
|
|
|
|
EXPORT_SYMBOL(ifx_ssc_cs_high); |
|
|
|
|
|
|
|
|
|
static int |
|
|
|
|
ssc_session (char *tx_buf, u32 tx_len, char *rx_buf, u32 rx_len) |
|
|
|
|
static int ssc_session(char *tx_buf, u32 tx_len, char *rx_buf, u32 rx_len) |
|
|
|
|
{ |
|
|
|
|
int ret = 0; |
|
|
|
|
|
|
|
|
@ -1283,61 +1225,47 @@ ssc_session (char *tx_buf, u32 tx_len, char *rx_buf, u32 rx_len) |
|
|
|
|
printk("invalid parameters\n"); |
|
|
|
|
ret = -EINVAL; |
|
|
|
|
goto ssc_session_exit; |
|
|
|
|
} |
|
|
|
|
else if (tx_buf == NULL || tx_len == 0) { |
|
|
|
|
} else if (tx_buf == NULL || tx_len == 0) { |
|
|
|
|
if (rx_buf != NULL && rx_len != 0) { |
|
|
|
|
mode = IFX_SSC_MODE_RX; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
} else { |
|
|
|
|
printk("invalid parameters\n"); |
|
|
|
|
ret = -EINVAL; |
|
|
|
|
goto ssc_session_exit; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else if (rx_buf == NULL || rx_len == 0) { |
|
|
|
|
if (tx_buf != NULL && tx_len != 0) { |
|
|
|
|
} else if (rx_buf == NULL || rx_len == 0) { |
|
|
|
|
if (tx_buf != NULL && tx_len != 0) |
|
|
|
|
mode = IFX_SSC_MODE_TX; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
printk("invalid parameters\n"); |
|
|
|
|
ret = -EINVAL; |
|
|
|
|
goto ssc_session_exit; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
} else |
|
|
|
|
mode = IFX_SSC_MODE_RXTX; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (mode == IFX_SSC_MODE_RXTX) { |
|
|
|
|
if (mode == IFX_SSC_MODE_RXTX) |
|
|
|
|
eff_size = tx_len + rx_len; |
|
|
|
|
} |
|
|
|
|
else if (mode == IFX_SSC_MODE_RX) { |
|
|
|
|
else if (mode == IFX_SSC_MODE_RX) |
|
|
|
|
eff_size = rx_len; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
else |
|
|
|
|
eff_size = tx_len; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//4 bytes alignment, required by driver
|
|
|
|
|
/* change by TaiCheng */ |
|
|
|
|
//if (in_irq()){
|
|
|
|
|
if (1) { |
|
|
|
|
ssc_tx_buf = |
|
|
|
|
(char *) kmalloc (sizeof (char) * |
|
|
|
|
ssc_tx_buf = kmalloc(sizeof(char) * |
|
|
|
|
((eff_size + 3) & (~3)), |
|
|
|
|
GFP_ATOMIC); |
|
|
|
|
ssc_rx_buf = |
|
|
|
|
(char *) kmalloc (sizeof (char) * |
|
|
|
|
ssc_rx_buf = kmalloc(sizeof(char) * |
|
|
|
|
((eff_size + 3) & (~3)), |
|
|
|
|
GFP_ATOMIC); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
ssc_tx_buf = |
|
|
|
|
(char *) kmalloc (sizeof (char) * |
|
|
|
|
} else { |
|
|
|
|
ssc_tx_buf = kmalloc(sizeof(char) * |
|
|
|
|
((eff_size + 3) & (~3)), |
|
|
|
|
GFP_KERNEL); |
|
|
|
|
ssc_rx_buf = |
|
|
|
|
(char *) kmalloc (sizeof (char) * |
|
|
|
|
ssc_rx_buf = kmalloc(sizeof(char) * |
|
|
|
|
((eff_size + 3) & (~3)), |
|
|
|
|
GFP_KERNEL); |
|
|
|
|
} |
|
|
|
@ -1349,15 +1277,13 @@ ssc_session (char *tx_buf, u32 tx_len, char *rx_buf, u32 rx_len) |
|
|
|
|
memset((void *)ssc_tx_buf, 0, eff_size); |
|
|
|
|
memset((void *)ssc_rx_buf, 0, eff_size); |
|
|
|
|
|
|
|
|
|
if (tx_len > 0) { |
|
|
|
|
if (tx_len > 0) |
|
|
|
|
memcpy(ssc_tx_buf, tx_buf, tx_len); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ret = ifx_ssc_kwrite(0, ssc_tx_buf, eff_size); |
|
|
|
|
|
|
|
|
|
if (ret > 0) { |
|
|
|
|
ssc_tx_buf = NULL; //should be freed by ifx_ssc_kwrite
|
|
|
|
|
} |
|
|
|
|
if (ret > 0) |
|
|
|
|
ssc_tx_buf = NULL; /* should be freed by ifx_ssc_kwrite */ |
|
|
|
|
|
|
|
|
|
if (ret != eff_size) { |
|
|
|
|
printk("ifx_ssc_write return %d\n", ret); |
|
|
|
@ -1371,41 +1297,36 @@ ssc_session (char *tx_buf, u32 tx_len, char *rx_buf, u32 rx_len) |
|
|
|
|
|
|
|
|
|
memcpy(rx_buf, ssc_rx_buf + tx_len, rx_len); |
|
|
|
|
|
|
|
|
|
if (mode == IFX_SSC_MODE_TX) { |
|
|
|
|
if (mode == IFX_SSC_MODE_TX) |
|
|
|
|
ret = tx_len; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
else |
|
|
|
|
ret = rx_len; |
|
|
|
|
} |
|
|
|
|
ssc_session_exit: |
|
|
|
|
|
|
|
|
|
ssc_session_exit: |
|
|
|
|
if (ssc_tx_buf != NULL) |
|
|
|
|
kfree(ssc_tx_buf); |
|
|
|
|
if (ssc_rx_buf != NULL) |
|
|
|
|
kfree(ssc_rx_buf); |
|
|
|
|
|
|
|
|
|
if (ret < 0) { |
|
|
|
|
if (ret < 0) |
|
|
|
|
printk("ssc session fails\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int |
|
|
|
|
ifx_ssc_txrx (char *tx_buf, u32 tx_len, char *rx_buf, u32 rx_len) |
|
|
|
|
int ifx_ssc_txrx(char *tx_buf, u32 tx_len, char *rx_buf, u32 rx_len) |
|
|
|
|
{ |
|
|
|
|
return ssc_session(tx_buf, tx_len, rx_buf, rx_len); |
|
|
|
|
} |
|
|
|
|
EXPORT_SYMBOL(ifx_ssc_txrx); |
|
|
|
|
|
|
|
|
|
int |
|
|
|
|
ifx_ssc_tx (char *tx_buf, u32 tx_len) |
|
|
|
|
int ifx_ssc_tx(char *tx_buf, u32 tx_len) |
|
|
|
|
{ |
|
|
|
|
return ssc_session(tx_buf, tx_len, NULL, 0); |
|
|
|
|
} |
|
|
|
|
EXPORT_SYMBOL(ifx_ssc_tx); |
|
|
|
|
|
|
|
|
|
int |
|
|
|
|
ifx_ssc_rx (char *rx_buf, u32 rx_len) |
|
|
|
|
int ifx_ssc_rx(char *rx_buf, u32 rx_len) |
|
|
|
|
{ |
|
|
|
|
return ssc_session(NULL, 0, rx_buf, rx_len); |
|
|
|
|
} |
|
|
|
|