2007-12-21 00:29:45 +02:00
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
2008-12-16 16:07:55 +02:00
|
|
|
* Copyright(C) 2006 infineon
|
|
|
|
* Copyright(C) 2007 John Crispin <blogic@openwrt.org>
|
2007-12-21 00:29:45 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
/*
|
|
|
|
### 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
|
|
|
|
*/
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/signal.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/major.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/fcntl.h>
|
|
|
|
#include <linux/ptrace.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/slab.h>
|
2008-12-16 16:07:55 +02:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/irq.h>
|
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <linux/bitops.h>
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/version.h>
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
#include <asm/system.h>
|
2007-12-22 15:55:14 +02:00
|
|
|
#include <asm/ifxmips/ifxmips.h>
|
|
|
|
#include <asm/ifxmips/ifxmips_irq.h>
|
|
|
|
#include <asm/ifxmips/ifx_ssc_defines.h>
|
|
|
|
#include <asm/ifxmips/ifx_ssc.h>
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
/* allow the user to set the major device number */
|
2008-12-16 16:07:55 +02:00
|
|
|
static int maj;
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the per-channel data structure containing pointers, flags
|
|
|
|
* and variables for the port. This driver supports a maximum of PORT_CNT.
|
|
|
|
* isp is allocated in ifx_ssc_init() based on the chip version.
|
|
|
|
*/
|
|
|
|
static struct ifx_ssc_port *isp;
|
|
|
|
|
|
|
|
/* other forward declarations */
|
2008-12-16 16:07:55 +02:00
|
|
|
static unsigned int ifx_ssc_get_kernel_clk(struct ifx_ssc_port *info);
|
|
|
|
static void tx_int(struct ifx_ssc_port *);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
extern unsigned int ifxmips_get_fpi_hz(void);
|
|
|
|
extern void ifxmips_mask_and_ack_irq(unsigned int irq_nr);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
static inline unsigned int ifx_ssc_get_kernel_clk(struct ifx_ssc_port *info)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
unsigned int rmc;
|
|
|
|
|
2008-06-07 19:04:31 +03:00
|
|
|
rmc = (ifxmips_r32(IFXMIPS_SSC_CLC) & IFX_CLC_RUN_DIVIDER_MASK) >> IFX_CLC_RUN_DIVIDER_OFFSET;
|
2008-12-16 16:07:55 +02:00
|
|
|
if (rmc == 0) {
|
|
|
|
printk("ifx_ssc_get_kernel_clk rmc==0 \n");
|
2007-12-21 00:29:45 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2008-12-16 16:07:55 +02:00
|
|
|
return ifxmips_get_fpi_hz() / rmc;
|
2007-12-21 00:29:45 +02:00
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
static inline void rx_int(struct ifx_ssc_port *info)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
int fifo_fill_lev, bytes_in_buf, i;
|
|
|
|
unsigned long tmp_val;
|
|
|
|
unsigned long *tmp_ptr;
|
|
|
|
unsigned int rx_valid_cnt;
|
|
|
|
/* number of words waiting in the RX FIFO */
|
2008-06-07 19:04:31 +03:00
|
|
|
fifo_fill_lev = (ifxmips_r32(IFXMIPS_SSC_FSTAT) & IFX_SSC_FSTAT_RECEIVED_WORDS_MASK) >> IFX_SSC_FSTAT_RECEIVED_WORDS_OFFSET;
|
2007-12-21 00:29:45 +02:00
|
|
|
bytes_in_buf = info->rxbuf_end - info->rxbuf_ptr;
|
2008-12-16 16:07:55 +02:00
|
|
|
/* transfer with 32 bits per entry */
|
2007-12-21 00:29:45 +02:00
|
|
|
while ((bytes_in_buf >= 4) && (fifo_fill_lev > 0)) {
|
2008-12-16 16:07:55 +02:00
|
|
|
tmp_ptr = (unsigned long *)info->rxbuf_ptr;
|
2008-06-07 19:04:31 +03:00
|
|
|
*tmp_ptr = ifxmips_r32(IFXMIPS_SSC_RB);
|
2007-12-21 00:29:45 +02:00
|
|
|
info->rxbuf_ptr += 4;
|
|
|
|
info->stats.rxBytes += 4;
|
|
|
|
fifo_fill_lev--;
|
|
|
|
bytes_in_buf -= 4;
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
/* now do the rest as mentioned in STATE.RXBV */
|
2007-12-21 00:29:45 +02:00
|
|
|
while ((bytes_in_buf > 0) && (fifo_fill_lev > 0)) {
|
2008-06-07 19:04:31 +03:00
|
|
|
rx_valid_cnt = (ifxmips_r32(IFXMIPS_SSC_STATE) & IFX_SSC_STATE_RX_BYTE_VALID_MASK) >> IFX_SSC_STATE_RX_BYTE_VALID_OFFSET;
|
2007-12-21 00:29:45 +02:00
|
|
|
if (rx_valid_cnt == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (rx_valid_cnt > bytes_in_buf)
|
|
|
|
rx_valid_cnt = bytes_in_buf;
|
|
|
|
|
2008-06-07 19:04:31 +03:00
|
|
|
tmp_val = ifxmips_r32(IFXMIPS_SSC_RB);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
for (i = 0; i < rx_valid_cnt; i++) {
|
2007-12-21 00:29:45 +02:00
|
|
|
*info->rxbuf_ptr = (tmp_val >> (8 * (rx_valid_cnt - i - 1))) & 0xff;
|
|
|
|
bytes_in_buf--;
|
|
|
|
info->rxbuf_ptr++;
|
|
|
|
}
|
|
|
|
info->stats.rxBytes += rx_valid_cnt;
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
/* check if transfer is complete */
|
|
|
|
if (info->rxbuf_ptr >= info->rxbuf_end) {
|
2007-12-22 23:21:38 +02:00
|
|
|
disable_irq(IFXMIPS_SSC_RIR);
|
2008-12-16 16:07:55 +02:00
|
|
|
wake_up_interruptible(&info->rwait);
|
|
|
|
} else if ((info->opts.modeRxTx == IFX_SSC_MODE_RX) && (ifxmips_r32(IFXMIPS_SSC_RXCNT) == 0)) {
|
2007-12-21 00:29:45 +02:00
|
|
|
if (info->rxbuf_end - info->rxbuf_ptr < IFX_SSC_RXREQ_BLOCK_SIZE)
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32((info->rxbuf_end - info->rxbuf_ptr) << IFX_SSC_RXREQ_RXCOUNT_OFFSET, IFXMIPS_SSC_RXREQ);
|
2007-12-21 00:29:45 +02:00
|
|
|
else
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32(IFX_SSC_RXREQ_BLOCK_SIZE << IFX_SSC_RXREQ_RXCOUNT_OFFSET, IFXMIPS_SSC_RXREQ);
|
2007-12-21 00:29:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
static inline void tx_int(struct ifx_ssc_port *info)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
int fifo_space, fill, i;
|
2008-06-07 19:04:31 +03:00
|
|
|
fifo_space = ((ifxmips_r32(IFXMIPS_SSC_ID) & IFX_SSC_PERID_TXFS_MASK) >> IFX_SSC_PERID_TXFS_OFFSET)
|
2008-12-16 16:07:55 +02:00
|
|
|
-((ifxmips_r32(IFXMIPS_SSC_FSTAT) & IFX_SSC_FSTAT_TRANSMIT_WORDS_MASK) >> IFX_SSC_FSTAT_TRANSMIT_WORDS_OFFSET);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
if (fifo_space == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fill = info->txbuf_end - info->txbuf_ptr;
|
|
|
|
|
|
|
|
if (fill > fifo_space * 4)
|
|
|
|
fill = fifo_space * 4;
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
for (i = 0; i < fill / 4; i++) {
|
|
|
|
/* at first 32 bit access */
|
|
|
|
ifxmips_w32(*(UINT32 *)info->txbuf_ptr, IFXMIPS_SSC_TB);
|
2007-12-21 00:29:45 +02:00
|
|
|
info->txbuf_ptr += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
fifo_space -= fill / 4;
|
|
|
|
info->stats.txBytes += fill & ~0x3;
|
|
|
|
fill &= 0x3;
|
2008-12-16 16:07:55 +02:00
|
|
|
if ((fifo_space > 0) & (fill > 1)) {
|
|
|
|
/* trailing 16 bit access */
|
|
|
|
WRITE_PERIPHERAL_REGISTER_16(*(UINT16 *)info->txbuf_ptr, info->mapbase + IFX_SSC_TB);
|
2007-12-21 00:29:45 +02:00
|
|
|
info->txbuf_ptr += 2;
|
|
|
|
info->stats.txBytes += 2;
|
|
|
|
fifo_space--;
|
|
|
|
fill -= 2;
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
if ((fifo_space > 0) & (fill > 0)) {
|
|
|
|
/* trailing 8 bit access */
|
|
|
|
WRITE_PERIPHERAL_REGISTER_8(*(UINT8 *)info->txbuf_ptr, info->mapbase + IFX_SSC_TB);
|
2007-12-21 00:29:45 +02:00
|
|
|
info->txbuf_ptr++;
|
|
|
|
info->stats.txBytes++;
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
/* check if transmission complete */
|
|
|
|
if (info->txbuf_ptr >= info->txbuf_end) {
|
2007-12-22 23:21:38 +02:00
|
|
|
disable_irq(IFXMIPS_SSC_TIR);
|
2008-12-16 16:07:55 +02:00
|
|
|
kfree(info->txbuf);
|
2007-12-21 00:29:45 +02:00
|
|
|
info->txbuf = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
irqreturn_t ifx_ssc_rx_int(int irq, void *dev_id)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
2008-12-16 16:07:55 +02:00
|
|
|
struct ifx_ssc_port *info = (struct ifx_ssc_port *)dev_id;
|
|
|
|
rx_int(info);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
irqreturn_t ifx_ssc_tx_int(int irq, void *dev_id)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
2008-12-16 16:07:55 +02:00
|
|
|
struct ifx_ssc_port *info = (struct ifx_ssc_port *)dev_id;
|
|
|
|
tx_int(info);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
irqreturn_t ifx_ssc_err_int(int irq, void *dev_id)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
2008-12-16 16:07:55 +02:00
|
|
|
struct ifx_ssc_port *info = (struct ifx_ssc_port *)dev_id;
|
2007-12-21 00:29:45 +02:00
|
|
|
unsigned int state;
|
|
|
|
unsigned int write_back = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
local_irq_save(flags);
|
2008-06-07 19:04:31 +03:00
|
|
|
state = ifxmips_r32(IFXMIPS_SSC_STATE);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
if ((state & IFX_SSC_STATE_RX_UFL) != 0) {
|
|
|
|
info->stats.rxUnErr++;
|
|
|
|
write_back |= IFX_SSC_WHBSTATE_CLR_RX_UFL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((state & IFX_SSC_STATE_RX_OFL) != 0) {
|
|
|
|
info->stats.rxOvErr++;
|
|
|
|
write_back |= IFX_SSC_WHBSTATE_CLR_RX_OFL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((state & IFX_SSC_STATE_TX_OFL) != 0) {
|
|
|
|
info->stats.txOvErr++;
|
|
|
|
write_back |= IFX_SSC_WHBSTATE_CLR_TX_OFL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((state & IFX_SSC_STATE_TX_UFL) != 0) {
|
|
|
|
info->stats.txUnErr++;
|
|
|
|
write_back |= IFX_SSC_WHBSTATE_CLR_TX_UFL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((state & IFX_SSC_STATE_MODE_ERR) != 0) {
|
|
|
|
info->stats.modeErr++;
|
|
|
|
write_back |= IFX_SSC_WHBSTATE_CLR_MODE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (write_back)
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32(write_back, IFXMIPS_SSC_WHBSTATE);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
local_irq_restore(flags);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
static void ifx_ssc_abort(struct ifx_ssc_port *info)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
bool enabled;
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
local_irq_save(flags);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2007-12-22 23:21:38 +02:00
|
|
|
disable_irq(IFXMIPS_SSC_RIR);
|
|
|
|
disable_irq(IFXMIPS_SSC_TIR);
|
|
|
|
disable_irq(IFXMIPS_SSC_EIR);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
local_irq_restore(flags);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
/* 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!
|
|
|
|
*/
|
2008-06-07 19:04:31 +03:00
|
|
|
enabled = (ifxmips_r32(IFXMIPS_SSC_STATE) & IFX_SSC_STATE_IS_ENABLED) != 0;
|
|
|
|
ifxmips_w32(IFX_SSC_WHBSTATE_CLR_ENABLE, IFXMIPS_SSC_WHBSTATE);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
/* flush fifos */
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32(IFX_SSC_XFCON_FIFO_FLUSH, IFXMIPS_SSC_TXFCON);
|
|
|
|
ifxmips_w32(IFX_SSC_XFCON_FIFO_FLUSH, IFXMIPS_SSC_RXFCON);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
/* free txbuf */
|
|
|
|
if (info->txbuf != NULL) {
|
|
|
|
kfree(info->txbuf);
|
2007-12-21 00:29:45 +02:00
|
|
|
info->txbuf = NULL;
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
/* wakeup read process */
|
2007-12-21 00:29:45 +02:00
|
|
|
if (info->rxbuf != NULL)
|
2008-12-16 16:07:55 +02:00
|
|
|
wake_up_interruptible(&info->rwait);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
/* clear pending int's */
|
2008-06-23 23:31:34 +03:00
|
|
|
ifxmips_mask_and_ack_irq(IFXMIPS_SSC_RIR);
|
|
|
|
ifxmips_mask_and_ack_irq(IFXMIPS_SSC_TIR);
|
|
|
|
ifxmips_mask_and_ack_irq(IFXMIPS_SSC_EIR);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
/* clear error flags */
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32(IFX_SSC_WHBSTATE_CLR_ALL_ERROR, IFXMIPS_SSC_WHBSTATE);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
if (enabled)
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32(IFX_SSC_WHBSTATE_SET_ENABLE, IFXMIPS_SSC_WHBSTATE);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This routine is called whenever a port is opened. It enforces
|
|
|
|
* exclusive opening of a port and enables interrupts, etc.
|
|
|
|
*/
|
2008-12-16 16:07:55 +02:00
|
|
|
int ifx_ssc_open(struct inode *inode, struct file *filp)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
struct ifx_ssc_port *info;
|
|
|
|
int line;
|
|
|
|
int from_kernel = 0;
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
if ((inode == (struct inode *)0) || (inode == (struct inode *)1)) {
|
2007-12-21 00:29:45 +02:00
|
|
|
from_kernel = 1;
|
|
|
|
line = (int) inode;
|
2008-12-16 16:07:55 +02:00
|
|
|
} else
|
|
|
|
line = MINOR(filp->f_dentry->d_inode->i_rdev);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
/* don't open more minor devices than we can support */
|
|
|
|
if (line < 0 || line >= PORT_CNT)
|
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
info = &isp[line];
|
|
|
|
|
|
|
|
/* exclusive open */
|
|
|
|
if (info->port_is_open != 0)
|
|
|
|
return -EBUSY;
|
|
|
|
info->port_is_open++;
|
|
|
|
|
2007-12-22 23:21:38 +02:00
|
|
|
disable_irq(IFXMIPS_SSC_RIR);
|
|
|
|
disable_irq(IFXMIPS_SSC_TIR);
|
|
|
|
disable_irq(IFXMIPS_SSC_EIR);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
/* Flush and enable TX/RX FIFO */
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32((IFX_SSC_DEF_TXFIFO_FL << IFX_SSC_XFCON_ITL_OFFSET) | IFX_SSC_XFCON_FIFO_FLUSH | IFX_SSC_XFCON_FIFO_ENABLE, IFXMIPS_SSC_TXFCON);
|
|
|
|
ifxmips_w32((IFX_SSC_DEF_RXFIFO_FL << IFX_SSC_XFCON_ITL_OFFSET) | IFX_SSC_XFCON_FIFO_FLUSH | IFX_SSC_XFCON_FIFO_ENABLE, IFXMIPS_SSC_RXFCON);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
/* logically flush the software FIFOs */
|
|
|
|
info->rxbuf_ptr = 0;
|
|
|
|
info->txbuf_ptr = 0;
|
|
|
|
|
|
|
|
/* clear all error bits */
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32(IFX_SSC_WHBSTATE_CLR_ALL_ERROR, IFXMIPS_SSC_WHBSTATE);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
/* clear pending interrupts */
|
2008-06-23 23:31:34 +03:00
|
|
|
ifxmips_mask_and_ack_irq(IFXMIPS_SSC_RIR);
|
|
|
|
ifxmips_mask_and_ack_irq(IFXMIPS_SSC_TIR);
|
|
|
|
ifxmips_mask_and_ack_irq(IFXMIPS_SSC_EIR);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32(IFX_SSC_WHBSTATE_SET_ENABLE, IFXMIPS_SSC_WHBSTATE);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ifx_ssc_open);
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
int ifx_ssc_close(struct inode *inode, struct file *filp)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
struct ifx_ssc_port *info;
|
|
|
|
int idx;
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
if ((inode == (struct inode *)0) || (inode == (struct inode *)1))
|
2007-12-21 00:29:45 +02:00
|
|
|
idx = (int) inode;
|
|
|
|
else
|
2008-12-16 16:07:55 +02:00
|
|
|
idx = MINOR(filp->f_dentry->d_inode->i_rdev);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
if (idx < 0 || idx >= PORT_CNT)
|
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
info = &isp[idx];
|
|
|
|
if (!info)
|
|
|
|
return -ENXIO;
|
|
|
|
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32(IFX_SSC_WHBSTATE_CLR_ENABLE, IFXMIPS_SSC_WHBSTATE);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
ifx_ssc_abort(info);
|
|
|
|
|
|
|
|
info->port_is_open--;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ifx_ssc_close);
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
static ssize_t ifx_ssc_read_helper_poll(struct ifx_ssc_port *info, char *buf,
|
|
|
|
size_t len, int from_kernel)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
ssize_t ret_val;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (info->opts.modeRxTx == IFX_SSC_MODE_TX)
|
|
|
|
return -EFAULT;
|
2008-12-16 16:07:55 +02:00
|
|
|
local_irq_save(flags);
|
2007-12-21 00:29:45 +02:00
|
|
|
info->rxbuf_ptr = info->rxbuf;
|
|
|
|
info->rxbuf_end = info->rxbuf + len;
|
2008-12-16 16:07:55 +02:00
|
|
|
local_irq_restore(flags);
|
2007-12-21 00:29:45 +02:00
|
|
|
/* Vinetic driver always works in IFX_SSC_MODE_RXTX */
|
|
|
|
/* TXRX in poll mode */
|
2008-12-16 16:07:55 +02:00
|
|
|
while (info->rxbuf_ptr < info->rxbuf_end) {
|
2007-12-21 00:29:45 +02:00
|
|
|
if (info->txbuf_ptr < info->txbuf_end)
|
2008-12-16 16:07:55 +02:00
|
|
|
tx_int(info);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
rx_int(info);
|
2007-12-21 00:29:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
ret_val = info->rxbuf_ptr - info->rxbuf;
|
|
|
|
|
|
|
|
return ret_val;
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
static ssize_t ifx_ssc_read_helper(struct ifx_ssc_port *info, char *buf,
|
|
|
|
size_t len, int from_kernel)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
ssize_t ret_val;
|
|
|
|
unsigned long flags;
|
2008-12-16 16:07:55 +02:00
|
|
|
DECLARE_WAITQUEUE(wait, current);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
if (info->opts.modeRxTx == IFX_SSC_MODE_TX)
|
|
|
|
return -EFAULT;
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
local_irq_save(flags);
|
2007-12-21 00:29:45 +02:00
|
|
|
info->rxbuf_ptr = info->rxbuf;
|
|
|
|
info->rxbuf_end = info->rxbuf + len;
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
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__);
|
2007-12-21 00:29:45 +02:00
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
local_irq_restore(flags);
|
2008-12-16 16:07:55 +02:00
|
|
|
tx_int(info);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
if (info->txbuf_ptr < info->txbuf_end)
|
2007-12-22 23:21:38 +02:00
|
|
|
enable_irq(IFXMIPS_SSC_TIR);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2007-12-22 23:21:38 +02:00
|
|
|
enable_irq(IFXMIPS_SSC_RIR);
|
2007-12-21 00:29:45 +02:00
|
|
|
} else {
|
|
|
|
local_irq_restore(flags);
|
2008-06-07 19:04:31 +03:00
|
|
|
if (ifxmips_r32(IFXMIPS_SSC_RXCNT) & IFX_SSC_RXCNT_TODO_MASK)
|
2007-12-21 00:29:45 +02:00
|
|
|
return -EBUSY;
|
2007-12-22 23:21:38 +02:00
|
|
|
enable_irq(IFXMIPS_SSC_RIR);
|
2007-12-21 00:29:45 +02:00
|
|
|
if (len < IFX_SSC_RXREQ_BLOCK_SIZE)
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32(len << IFX_SSC_RXREQ_RXCOUNT_OFFSET, IFXMIPS_SSC_RXREQ);
|
2007-12-21 00:29:45 +02:00
|
|
|
else
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32(IFX_SSC_RXREQ_BLOCK_SIZE << IFX_SSC_RXREQ_RXCOUNT_OFFSET, IFXMIPS_SSC_RXREQ);
|
2007-12-21 00:29:45 +02:00
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
__add_wait_queue(&info->rwait, &wait);
|
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
do {
|
2008-12-16 16:07:55 +02:00
|
|
|
local_irq_save(flags);
|
2007-12-21 00:29:45 +02:00
|
|
|
if (info->rxbuf_ptr >= info->rxbuf_end)
|
|
|
|
break;
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
local_irq_restore(flags);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
if (signal_pending(current)) {
|
2007-12-21 00:29:45 +02:00
|
|
|
ret_val = -ERESTARTSYS;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
schedule();
|
|
|
|
} while (1);
|
|
|
|
|
|
|
|
ret_val = info->rxbuf_ptr - info->rxbuf;
|
2008-12-16 16:07:55 +02:00
|
|
|
local_irq_restore(flags);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
out:
|
|
|
|
current->state = TASK_RUNNING;
|
2008-12-16 16:07:55 +02:00
|
|
|
__remove_wait_queue(&info->rwait, &wait);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
return ret_val;
|
2007-12-21 00:29:45 +02:00
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
static ssize_t ifx_ssc_write_helper(struct ifx_ssc_port *info, const char *buf,
|
|
|
|
size_t len, int from_kernel)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
if (info->opts.modeRxTx == IFX_SSC_MODE_RX)
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
info->txbuf_ptr = info->txbuf;
|
|
|
|
info->txbuf_end = len + info->txbuf;
|
2008-12-16 16:07:55 +02:00
|
|
|
if (info->opts.modeRxTx == IFX_SSC_MODE_TX) {
|
|
|
|
tx_int(info);
|
2007-12-21 00:29:45 +02:00
|
|
|
if (info->txbuf_ptr < info->txbuf_end)
|
2007-12-22 23:21:38 +02:00
|
|
|
enable_irq(IFXMIPS_SSC_TIR);
|
2007-12-21 00:29:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
ssize_t ifx_ssc_kread(int port, char *kbuf, size_t len)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
struct ifx_ssc_port *info;
|
|
|
|
ssize_t ret_val;
|
|
|
|
|
|
|
|
if (port < 0 || port >= PORT_CNT)
|
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
info = &isp[port];
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
if (info->rxbuf != NULL) {
|
|
|
|
printk("SSC device busy\n");
|
2007-12-21 00:29:45 +02:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
info->rxbuf = kbuf;
|
2008-12-16 16:07:55 +02:00
|
|
|
if (info->rxbuf == NULL) {
|
|
|
|
printk("SSC device error\n");
|
2007-12-21 00:29:45 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
ret_val = ifx_ssc_read_helper_poll(info, kbuf, len, 1);
|
2007-12-21 00:29:45 +02:00
|
|
|
info->rxbuf = NULL;
|
|
|
|
|
2007-12-22 23:21:38 +02:00
|
|
|
disable_irq(IFXMIPS_SSC_RIR);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
return ret_val;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ifx_ssc_kread);
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
ssize_t ifx_ssc_kwrite(int port, const char *kbuf, size_t len)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
struct ifx_ssc_port *info;
|
|
|
|
ssize_t ret_val;
|
|
|
|
|
|
|
|
if (port < 0 || port >= PORT_CNT)
|
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
info = &isp[port];
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
/* check if transmission in progress */
|
2007-12-21 00:29:45 +02:00
|
|
|
if (info->txbuf != NULL)
|
|
|
|
return -EBUSY;
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
info->txbuf = (char *)kbuf;
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
ret_val = ifx_ssc_write_helper(info, info->txbuf, len, 1);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
if (ret_val < 0)
|
|
|
|
info->txbuf = NULL;
|
|
|
|
|
|
|
|
return ret_val;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ifx_ssc_kwrite);
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
static ssize_t ifx_ssc_read(struct file *filp, char *ubuf, size_t len, loff_t *off)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
ssize_t ret_val;
|
|
|
|
int idx;
|
|
|
|
struct ifx_ssc_port *info;
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
idx = MINOR(filp->f_dentry->d_inode->i_rdev);
|
2007-12-21 00:29:45 +02:00
|
|
|
info = &isp[idx];
|
|
|
|
|
|
|
|
if (info->rxbuf != NULL)
|
|
|
|
return -EBUSY;
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
info->rxbuf = kmalloc(len + 3, GFP_KERNEL);
|
2007-12-21 00:29:45 +02:00
|
|
|
if (info->rxbuf == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
ret_val = ifx_ssc_read_helper(info, info->rxbuf, len, 0);
|
|
|
|
if (copy_to_user((void *)ubuf, info->rxbuf, ret_val) != 0)
|
2007-12-21 00:29:45 +02:00
|
|
|
ret_val = -EFAULT;
|
|
|
|
|
2007-12-22 23:21:38 +02:00
|
|
|
disable_irq(IFXMIPS_SSC_RIR);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
kfree(info->rxbuf);
|
2007-12-21 00:29:45 +02:00
|
|
|
info->rxbuf = NULL;
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
return ret_val;
|
2007-12-21 00:29:45 +02:00
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
static ssize_t ifx_ssc_write(struct file *filp, const char *ubuf, size_t len, loff_t *off)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
struct ifx_ssc_port *info;
|
|
|
|
int ret_val;
|
|
|
|
|
|
|
|
if (len == 0)
|
2008-12-16 16:07:55 +02:00
|
|
|
return 0;
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
idx = MINOR(filp->f_dentry->d_inode->i_rdev);
|
2007-12-21 00:29:45 +02:00
|
|
|
info = &isp[idx];
|
|
|
|
|
|
|
|
if (info->txbuf != NULL)
|
|
|
|
return -EBUSY;
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
info->txbuf = kmalloc(len + 3, GFP_KERNEL);
|
2007-12-21 00:29:45 +02:00
|
|
|
if (info->txbuf == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
ret_val = copy_from_user(info->txbuf, ubuf, len);
|
2007-12-21 00:29:45 +02:00
|
|
|
if (ret_val == 0)
|
2008-12-16 16:07:55 +02:00
|
|
|
ret_val = ifx_ssc_write_helper(info, info->txbuf, len, 0);
|
2007-12-21 00:29:45 +02:00
|
|
|
else
|
|
|
|
ret_val = -EFAULT;
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
if (ret_val < 0) {
|
|
|
|
kfree(info->txbuf);
|
2007-12-21 00:29:45 +02:00
|
|
|
info->txbuf = NULL;
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
return ret_val;
|
2007-12-21 00:29:45 +02:00
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
static struct ifx_ssc_frm_status *ifx_ssc_frm_status_get(struct ifx_ssc_port *info)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
unsigned long tmp;
|
|
|
|
|
2008-06-07 19:04:31 +03:00
|
|
|
tmp = ifxmips_r32(IFXMIPS_SSC_SFSTAT);
|
2007-12-21 00:29:45 +02:00
|
|
|
info->frm_status.DataBusy = (tmp & IFX_SSC_SFSTAT_IN_DATA) > 0;
|
|
|
|
info->frm_status.PauseBusy = (tmp & IFX_SSC_SFSTAT_IN_PAUSE) > 0;
|
|
|
|
info->frm_status.DataCount = (tmp & IFX_SSC_SFSTAT_DATA_COUNT_MASK) >> IFX_SSC_SFSTAT_DATA_COUNT_OFFSET;
|
|
|
|
info->frm_status.PauseCount = (tmp & IFX_SSC_SFSTAT_PAUSE_COUNT_MASK) >> IFX_SSC_SFSTAT_PAUSE_COUNT_OFFSET;
|
2008-06-07 19:04:31 +03:00
|
|
|
tmp = ifxmips_r32(IFXMIPS_SSC_SFCON);
|
2007-12-21 00:29:45 +02:00
|
|
|
info->frm_status.EnIntAfterData = (tmp & IFX_SSC_SFCON_FIR_ENABLE_BEFORE_PAUSE) > 0;
|
|
|
|
info->frm_status.EnIntAfterPause = (tmp & IFX_SSC_SFCON_FIR_ENABLE_AFTER_PAUSE) > 0;
|
|
|
|
|
|
|
|
return &info->frm_status;
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
static struct ifx_ssc_frm_opts *ifx_ssc_frm_control_get(struct ifx_ssc_port *info)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
unsigned long tmp;
|
|
|
|
|
2008-06-07 19:04:31 +03:00
|
|
|
tmp = ifxmips_r32(IFXMIPS_SSC_SFCON);
|
2007-12-21 00:29:45 +02:00
|
|
|
info->frm_opts.FrameEnable = (tmp & IFX_SSC_SFCON_SF_ENABLE) > 0;
|
|
|
|
info->frm_opts.DataLength = (tmp & IFX_SSC_SFCON_DATA_LENGTH_MASK) >> IFX_SSC_SFCON_DATA_LENGTH_OFFSET;
|
|
|
|
info->frm_opts.PauseLength = (tmp & IFX_SSC_SFCON_PAUSE_LENGTH_MASK) >> IFX_SSC_SFCON_PAUSE_LENGTH_OFFSET;
|
|
|
|
info->frm_opts.IdleData = (tmp & IFX_SSC_SFCON_PAUSE_DATA_MASK) >> IFX_SSC_SFCON_PAUSE_DATA_OFFSET;
|
|
|
|
info->frm_opts.IdleClock = (tmp & IFX_SSC_SFCON_PAUSE_CLOCK_MASK) >> IFX_SSC_SFCON_PAUSE_CLOCK_OFFSET;
|
|
|
|
info->frm_opts.StopAfterPause = (tmp & IFX_SSC_SFCON_STOP_AFTER_PAUSE) > 0;
|
|
|
|
|
|
|
|
return &info->frm_opts;
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
static int ifx_ssc_frm_control_set(struct ifx_ssc_port *info)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
unsigned long tmp;
|
|
|
|
|
|
|
|
if ((info->frm_opts.DataLength > IFX_SSC_SFCON_DATA_LENGTH_MAX)
|
|
|
|
|| (info->frm_opts.DataLength < 1)
|
|
|
|
|| (info->frm_opts.PauseLength > IFX_SSC_SFCON_PAUSE_LENGTH_MAX)
|
|
|
|
|| (info->frm_opts.PauseLength < 1)
|
|
|
|
|| (info->frm_opts.IdleData & ~(IFX_SSC_SFCON_PAUSE_DATA_MASK >> IFX_SSC_SFCON_PAUSE_DATA_OFFSET))
|
|
|
|
|| (info->frm_opts.IdleClock & ~(IFX_SSC_SFCON_PAUSE_CLOCK_MASK >> IFX_SSC_SFCON_PAUSE_CLOCK_OFFSET)))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
/* read interrupt bits(they're not changed here) */
|
2008-06-07 19:04:31 +03:00
|
|
|
tmp = ifxmips_r32(IFXMIPS_SSC_SFCON) &
|
2007-12-21 00:29:45 +02:00
|
|
|
(IFX_SSC_SFCON_FIR_ENABLE_BEFORE_PAUSE | IFX_SSC_SFCON_FIR_ENABLE_AFTER_PAUSE);
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
/* set all values with respect to it's bit position(for data and pause
|
|
|
|
length set N-1) */
|
2007-12-21 00:29:45 +02:00
|
|
|
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;
|
|
|
|
tmp |= info->frm_opts.IdleClock << IFX_SSC_SFCON_PAUSE_CLOCK_OFFSET;
|
|
|
|
tmp |= info->frm_opts.FrameEnable * IFX_SSC_SFCON_SF_ENABLE;
|
|
|
|
tmp |= info->frm_opts.StopAfterPause * IFX_SSC_SFCON_STOP_AFTER_PAUSE;
|
|
|
|
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32(tmp, IFXMIPS_SSC_SFCON);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
static int ifx_ssc_rxtx_mode_set(struct ifx_ssc_port *info, unsigned int val)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
unsigned long tmp;
|
|
|
|
|
|
|
|
if (!(info) || (val & ~(IFX_SSC_MODE_MASK)))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2008-06-07 19:04:31 +03:00
|
|
|
if ((ifxmips_r32(IFXMIPS_SSC_STATE) & IFX_SSC_STATE_BUSY)
|
|
|
|
|| (ifxmips_r32(IFXMIPS_SSC_RXCNT) & IFX_SSC_RXCNT_TODO_MASK))
|
2007-12-21 00:29:45 +02:00
|
|
|
return -EBUSY;
|
|
|
|
|
2008-06-07 19:04:31 +03:00
|
|
|
tmp = (ifxmips_r32(IFXMIPS_SSC_CON) & ~(IFX_SSC_CON_RX_OFF | IFX_SSC_CON_TX_OFF)) | (val);
|
|
|
|
ifxmips_w32(tmp, IFXMIPS_SSC_SFCON);
|
2007-12-21 00:29:45 +02:00
|
|
|
info->opts.modeRxTx = val;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
static int ifx_ssc_sethwopts(struct ifx_ssc_port *info)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
unsigned long flags, bits;
|
|
|
|
struct ifx_ssc_hwopts *opts = &info->opts;
|
|
|
|
|
|
|
|
if ((opts->dataWidth < IFX_SSC_MIN_DATA_WIDTH)
|
|
|
|
|| (opts->dataWidth > IFX_SSC_MAX_DATA_WIDTH))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
bits = (opts->dataWidth - 1) << IFX_SSC_CON_DATA_WIDTH_OFFSET;
|
|
|
|
bits |= IFX_SSC_CON_ENABLE_BYTE_VALID;
|
|
|
|
|
|
|
|
if (opts->rxOvErrDetect)
|
|
|
|
bits |= IFX_SSC_CON_RX_OFL_CHECK;
|
|
|
|
if (opts->rxUndErrDetect)
|
|
|
|
bits |= IFX_SSC_CON_RX_UFL_CHECK;
|
|
|
|
if (opts->txOvErrDetect)
|
|
|
|
bits |= IFX_SSC_CON_TX_OFL_CHECK;
|
|
|
|
if (opts->txUndErrDetect)
|
|
|
|
bits |= IFX_SSC_CON_TX_UFL_CHECK;
|
|
|
|
if (opts->loopBack)
|
|
|
|
bits |= IFX_SSC_CON_LOOPBACK_MODE;
|
|
|
|
if (opts->echoMode)
|
|
|
|
bits |= IFX_SSC_CON_ECHO_MODE_ON;
|
|
|
|
if (opts->headingControl)
|
|
|
|
bits |= IFX_SSC_CON_MSB_FIRST;
|
|
|
|
if (opts->clockPhase)
|
|
|
|
bits |= IFX_SSC_CON_LATCH_THEN_SHIFT;
|
|
|
|
if (opts->clockPolarity)
|
|
|
|
bits |= IFX_SSC_CON_CLOCK_FALL;
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
switch (opts->modeRxTx) {
|
2007-12-21 00:29:45 +02:00
|
|
|
case IFX_SSC_MODE_TX:
|
|
|
|
bits |= IFX_SSC_CON_RX_OFF;
|
|
|
|
break;
|
|
|
|
case IFX_SSC_MODE_RX:
|
|
|
|
bits |= IFX_SSC_CON_TX_OFF;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
local_irq_save(flags);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32(bits, IFXMIPS_SSC_CON);
|
|
|
|
ifxmips_w32((info->opts.gpoCs << IFX_SSC_GPOCON_ISCSB0_POS) |
|
2008-12-16 16:07:55 +02:00
|
|
|
(info->opts.gpoInv << IFX_SSC_GPOCON_INVOUT0_POS), IFXMIPS_SSC_GPOCON);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32(info->opts.gpoCs << IFX_SSC_WHBGPOSTAT_SETOUT0_POS, IFXMIPS_SSC_WHBGPOSTAT);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
/* master mode */
|
2007-12-21 00:29:45 +02:00
|
|
|
if (opts->masterSelect)
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32(IFX_SSC_WHBSTATE_SET_MASTER_SELECT, IFXMIPS_SSC_WHBSTATE);
|
2007-12-21 00:29:45 +02:00
|
|
|
else
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32(IFX_SSC_WHBSTATE_CLR_MASTER_SELECT, IFXMIPS_SSC_WHBSTATE);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
/* init serial framing */
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32(0, IFXMIPS_SSC_SFCON);
|
2007-12-21 00:29:45 +02:00
|
|
|
/* set up the port pins */
|
2008-12-16 16:07:55 +02:00
|
|
|
/* check for general requirements to switch(external) pad/pin characteristics */
|
2007-12-21 00:29:45 +02:00
|
|
|
/* 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, */
|
2008-12-16 16:07:55 +02:00
|
|
|
/* Set p0.15 to alternative 01, others to 00(In/OUT) */
|
2007-12-22 02:17:22 +02:00
|
|
|
*(IFXMIPS_GPIO_P0_DIR) = (*IFXMIPS_GPIO_P0_DIR) | (0xA000);
|
|
|
|
*(IFXMIPS_GPIO_P0_ALTSEL0) = (((*IFXMIPS_GPIO_P0_ALTSEL0) | (0x8000)) & (~(0x2000)));
|
|
|
|
*(IFXMIPS_GPIO_P0_ALTSEL1) = (((*IFXMIPS_GPIO_P0_ALTSEL1) & (~0x8000)) & (~(0x2000)));
|
|
|
|
*(IFXMIPS_GPIO_P0_OD) = (*IFXMIPS_GPIO_P0_OD) | 0xA000;
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
/* p1.6 SPI_CS2(SFLASH), p1.0 SPI_DIN, p1.1 SPI_DOUT, p1.2 SPI_CLK */
|
2007-12-22 02:17:22 +02:00
|
|
|
*(IFXMIPS_GPIO_P1_DIR) = ((*IFXMIPS_GPIO_P1_DIR) | (0x46)) & (~1);
|
|
|
|
*(IFXMIPS_GPIO_P1_ALTSEL0) = ((*IFXMIPS_GPIO_P1_ALTSEL0) | (0x47));
|
|
|
|
*(IFXMIPS_GPIO_P1_ALTSEL1) = (*IFXMIPS_GPIO_P1_ALTSEL1) & (~0x47);
|
|
|
|
*(IFXMIPS_GPIO_P1_OD) = (*IFXMIPS_GPIO_P1_OD) | 0x0046;
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
/*CS3 */
|
|
|
|
/*TODO: CS4 CS5 CS6 */
|
2007-12-22 02:17:22 +02:00
|
|
|
*IFXMIPS_GPIO_P0_OUT = ((*IFXMIPS_GPIO_P0_OUT) | 0x2000);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
local_irq_restore(flags);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
static int ifx_ssc_set_baud(struct ifx_ssc_port *info, unsigned int baud)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
unsigned int ifx_ssc_clock;
|
|
|
|
unsigned int br;
|
|
|
|
unsigned long flags;
|
|
|
|
bool enabled;
|
|
|
|
int retval = 0;
|
|
|
|
|
|
|
|
ifx_ssc_clock = ifx_ssc_get_kernel_clk(info);
|
2008-12-16 16:07:55 +02:00
|
|
|
if (ifx_ssc_clock == 0) {
|
2007-12-21 00:29:45 +02:00
|
|
|
retval = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
local_irq_save(flags);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-06-07 19:04:31 +03:00
|
|
|
enabled = (ifxmips_r32(IFXMIPS_SSC_STATE) & IFX_SSC_STATE_IS_ENABLED);
|
|
|
|
ifxmips_w32(IFX_SSC_WHBSTATE_CLR_ENABLE, IFXMIPS_SSC_WHBSTATE);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
br = (((ifx_ssc_clock >> 1) + baud / 2) / baud) - 1;
|
|
|
|
wmb();
|
|
|
|
|
|
|
|
if (br > 0xffff || ((br == 0) &&
|
2008-06-07 19:04:31 +03:00
|
|
|
((ifxmips_r32(IFXMIPS_SSC_STATE) & IFX_SSC_STATE_IS_MASTER) == 0))) {
|
2008-12-16 16:07:55 +02:00
|
|
|
local_irq_restore(flags);
|
|
|
|
printk("%s: invalid baudrate %u\n", __func__, baud);
|
2007-12-21 00:29:45 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32(br, IFXMIPS_SSC_BR);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
if (enabled)
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32(IFX_SSC_WHBSTATE_SET_ENABLE, IFXMIPS_SSC_WHBSTATE);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
out:
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
static int ifx_ssc_hwinit(struct ifx_ssc_port *info)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
bool enabled;
|
|
|
|
|
2008-06-07 19:04:31 +03:00
|
|
|
enabled = (ifxmips_r32(IFXMIPS_SSC_STATE) & IFX_SSC_STATE_IS_ENABLED);
|
|
|
|
ifxmips_w32(IFX_SSC_WHBSTATE_CLR_ENABLE, IFXMIPS_SSC_WHBSTATE);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
if (ifx_ssc_sethwopts(info) < 0) {
|
|
|
|
printk("%s: setting the hardware options failed\n", __func__);
|
2007-12-21 00:29:45 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
if (ifx_ssc_set_baud(info, info->baud) < 0) {
|
|
|
|
printk("%s: setting the baud rate failed\n", __func__);
|
2007-12-21 00:29:45 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
local_irq_save(flags);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
/* TX FIFO */
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32((IFX_SSC_DEF_TXFIFO_FL << IFX_SSC_XFCON_ITL_OFFSET) | IFX_SSC_XFCON_FIFO_ENABLE, IFXMIPS_SSC_TXFCON);
|
2007-12-21 00:29:45 +02:00
|
|
|
/* RX FIFO */
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32((IFX_SSC_DEF_RXFIFO_FL << IFX_SSC_XFCON_ITL_OFFSET) | IFX_SSC_XFCON_FIFO_ENABLE, IFXMIPS_SSC_RXFCON);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
local_irq_restore(flags);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
if (enabled)
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32(IFX_SSC_WHBSTATE_SET_ENABLE, IFXMIPS_SSC_WHBSTATE);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
int ifx_ssc_ioctl(struct inode *inode, struct file *filp,
|
|
|
|
unsigned int cmd, unsigned long data)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
struct ifx_ssc_port *info;
|
|
|
|
int line, ret_val = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned long tmp;
|
|
|
|
int from_kernel = 0;
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
if ((inode == (struct inode *)0) || (inode == (struct inode *)1)) {
|
2007-12-21 00:29:45 +02:00
|
|
|
from_kernel = 1;
|
|
|
|
line = (int) inode;
|
2008-12-16 16:07:55 +02:00
|
|
|
} else
|
|
|
|
line = MINOR(filp->f_dentry->d_inode->i_rdev);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
if (line < 0 || line >= PORT_CNT)
|
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
info = &isp[line];
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
switch (cmd) {
|
2007-12-21 00:29:45 +02:00
|
|
|
case IFX_SSC_STATS_READ:
|
|
|
|
/* data must be a pointer to a struct ifx_ssc_statistics */
|
|
|
|
if (from_kernel)
|
2008-12-16 16:07:55 +02:00
|
|
|
memcpy((void *)data, (void *)&info->stats,
|
|
|
|
sizeof(struct ifx_ssc_statistics));
|
|
|
|
else if (copy_to_user((void *)data,
|
|
|
|
(void *)&info->stats,
|
|
|
|
sizeof(struct ifx_ssc_statistics)))
|
2007-12-21 00:29:45 +02:00
|
|
|
ret_val = -EFAULT;
|
|
|
|
break;
|
|
|
|
case IFX_SSC_STATS_RESET:
|
|
|
|
/* just resets the statistics counters */
|
2008-12-16 16:07:55 +02:00
|
|
|
memset((void *)&info->stats, 0,
|
|
|
|
sizeof(struct ifx_ssc_statistics));
|
2007-12-21 00:29:45 +02:00
|
|
|
break;
|
|
|
|
case IFX_SSC_BAUD_SET:
|
|
|
|
/* if the buffers are not empty then the port is */
|
|
|
|
/* busy and we shouldn't change things on-the-fly! */
|
|
|
|
if (!info->txbuf || !info->rxbuf ||
|
2008-12-16 16:07:55 +02:00
|
|
|
(ifxmips_r32(IFXMIPS_SSC_STATE) & IFX_SSC_STATE_BUSY)) {
|
2007-12-21 00:29:45 +02:00
|
|
|
ret_val = -EBUSY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* misuse flags */
|
|
|
|
if (from_kernel)
|
2008-12-16 16:07:55 +02:00
|
|
|
flags = *((unsigned long *)data);
|
|
|
|
else if (copy_from_user((void *)&flags,
|
|
|
|
(void *)data, sizeof(flags))) {
|
2007-12-21 00:29:45 +02:00
|
|
|
ret_val = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (flags == 0) {
|
|
|
|
ret_val = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2008-12-16 16:07:55 +02:00
|
|
|
if (ifx_ssc_set_baud(info, flags) < 0) {
|
2007-12-21 00:29:45 +02:00
|
|
|
ret_val = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
info->baud = flags;
|
|
|
|
break;
|
|
|
|
case IFX_SSC_BAUD_GET:
|
|
|
|
if (from_kernel)
|
2008-12-16 16:07:55 +02:00
|
|
|
*((unsigned int *)data) = info->baud;
|
|
|
|
else if (copy_to_user((void *)data,
|
|
|
|
(void *)&info->baud,
|
|
|
|
sizeof(unsigned long)))
|
2007-12-21 00:29:45 +02:00
|
|
|
ret_val = -EFAULT;
|
|
|
|
break;
|
|
|
|
case IFX_SSC_RXTX_MODE_SET:
|
|
|
|
if (from_kernel)
|
2008-12-16 16:07:55 +02:00
|
|
|
tmp = *((unsigned long *)data);
|
|
|
|
else if (copy_from_user((void *)&tmp,
|
|
|
|
(void *)data, sizeof(tmp))) {
|
2007-12-21 00:29:45 +02:00
|
|
|
ret_val = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
2008-12-16 16:07:55 +02:00
|
|
|
ret_val = ifx_ssc_rxtx_mode_set(info, tmp);
|
2007-12-21 00:29:45 +02:00
|
|
|
break;
|
|
|
|
case IFX_SSC_RXTX_MODE_GET:
|
2008-06-07 19:04:31 +03:00
|
|
|
tmp = ifxmips_r32(IFXMIPS_SSC_CON) &
|
2007-12-21 00:29:45 +02:00
|
|
|
(~(IFX_SSC_CON_RX_OFF | IFX_SSC_CON_TX_OFF));
|
|
|
|
if (from_kernel)
|
2008-12-16 16:07:55 +02:00
|
|
|
*((unsigned int *)data) = tmp;
|
|
|
|
else if (copy_to_user((void *)data,
|
|
|
|
(void *)&tmp, sizeof(tmp)))
|
2007-12-21 00:29:45 +02:00
|
|
|
ret_val = -EFAULT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IFX_SSC_ABORT:
|
2008-12-16 16:07:55 +02:00
|
|
|
ifx_ssc_abort(info);
|
2007-12-21 00:29:45 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IFX_SSC_GPO_OUT_SET:
|
|
|
|
if (from_kernel)
|
2008-12-16 16:07:55 +02:00
|
|
|
tmp = *((unsigned long *)data);
|
|
|
|
else if (copy_from_user((void *)&tmp,
|
|
|
|
(void *)data, sizeof(tmp))) {
|
2007-12-21 00:29:45 +02:00
|
|
|
ret_val = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (tmp > IFX_SSC_MAX_GPO_OUT)
|
|
|
|
ret_val = -EINVAL;
|
|
|
|
else
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32(1 << (tmp + IFX_SSC_WHBGPOSTAT_SETOUT0_POS),
|
2007-12-22 22:55:20 +02:00
|
|
|
IFXMIPS_SSC_WHBGPOSTAT);
|
2007-12-21 00:29:45 +02:00
|
|
|
break;
|
|
|
|
case IFX_SSC_GPO_OUT_CLR:
|
|
|
|
if (from_kernel)
|
2008-12-16 16:07:55 +02:00
|
|
|
tmp = *((unsigned long *)data);
|
|
|
|
else if (copy_from_user((void *)&tmp, (void *)data, sizeof(tmp))) {
|
2007-12-21 00:29:45 +02:00
|
|
|
ret_val = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (tmp > IFX_SSC_MAX_GPO_OUT)
|
|
|
|
ret_val = -EINVAL;
|
2008-12-16 16:07:55 +02:00
|
|
|
else
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32(1 << (tmp + IFX_SSC_WHBGPOSTAT_CLROUT0_POS),
|
2007-12-22 22:55:20 +02:00
|
|
|
IFXMIPS_SSC_WHBGPOSTAT);
|
2007-12-21 00:29:45 +02:00
|
|
|
break;
|
|
|
|
case IFX_SSC_GPO_OUT_GET:
|
2008-06-07 19:04:31 +03:00
|
|
|
tmp = ifxmips_r32(IFXMIPS_SSC_GPOSTAT);
|
2007-12-21 00:29:45 +02:00
|
|
|
if (from_kernel)
|
2008-12-16 16:07:55 +02:00
|
|
|
*((unsigned int *)data) = tmp;
|
|
|
|
else if (copy_to_user((void *)data,
|
|
|
|
(void *)&tmp, sizeof(tmp)))
|
2007-12-21 00:29:45 +02:00
|
|
|
ret_val = -EFAULT;
|
|
|
|
break;
|
|
|
|
case IFX_SSC_FRM_STATUS_GET:
|
2008-12-16 16:07:55 +02:00
|
|
|
ifx_ssc_frm_status_get(info);
|
2007-12-21 00:29:45 +02:00
|
|
|
if (from_kernel)
|
2008-12-16 16:07:55 +02:00
|
|
|
memcpy((void *)data, (void *)&info->frm_status,
|
|
|
|
sizeof(struct ifx_ssc_frm_status));
|
|
|
|
else if (copy_to_user((void *)data,
|
|
|
|
(void *)&info->frm_status,
|
|
|
|
sizeof(struct ifx_ssc_frm_status)))
|
2007-12-21 00:29:45 +02:00
|
|
|
ret_val = -EFAULT;
|
|
|
|
break;
|
|
|
|
case IFX_SSC_FRM_CONTROL_GET:
|
2008-12-16 16:07:55 +02:00
|
|
|
ifx_ssc_frm_control_get(info);
|
2007-12-21 00:29:45 +02:00
|
|
|
if (from_kernel)
|
2008-12-16 16:07:55 +02:00
|
|
|
memcpy((void *)data, (void *)&info->frm_opts,
|
|
|
|
sizeof(struct ifx_ssc_frm_opts));
|
|
|
|
else if (copy_to_user((void *)data,
|
|
|
|
(void *)&info->frm_opts,
|
|
|
|
sizeof(struct ifx_ssc_frm_opts)))
|
2007-12-21 00:29:45 +02:00
|
|
|
ret_val = -EFAULT;
|
|
|
|
break;
|
|
|
|
case IFX_SSC_FRM_CONTROL_SET:
|
|
|
|
if (from_kernel)
|
2008-12-16 16:07:55 +02:00
|
|
|
memcpy((void *)&info->frm_opts, (void *)data,
|
|
|
|
sizeof(struct ifx_ssc_frm_opts));
|
|
|
|
else if (copy_to_user((void *)&info->frm_opts,
|
|
|
|
(void *)data,
|
|
|
|
sizeof(struct ifx_ssc_frm_opts))) {
|
2007-12-21 00:29:45 +02:00
|
|
|
ret_val = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
2008-12-16 16:07:55 +02:00
|
|
|
ret_val = ifx_ssc_frm_control_set(info);
|
2007-12-21 00:29:45 +02:00
|
|
|
break;
|
|
|
|
case IFX_SSC_HWOPTS_SET:
|
|
|
|
/* data must be a pointer to a struct ifx_ssc_hwopts */
|
|
|
|
/* if the buffers are not empty then the port is */
|
|
|
|
/* busy and we shouldn't change things on-the-fly! */
|
|
|
|
if (!info->txbuf || !info->rxbuf ||
|
2008-12-16 16:07:55 +02:00
|
|
|
(ifxmips_r32(IFXMIPS_SSC_STATE)
|
2007-12-21 00:29:45 +02:00
|
|
|
& IFX_SSC_STATE_BUSY)) {
|
|
|
|
ret_val = -EBUSY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (from_kernel)
|
2008-12-16 16:07:55 +02:00
|
|
|
memcpy((void *)&info->opts, (void *)data,
|
|
|
|
sizeof(struct ifx_ssc_hwopts));
|
|
|
|
else if (copy_from_user((void *)&info->opts,
|
|
|
|
(void *)data, sizeof(struct ifx_ssc_hwopts))) {
|
2007-12-21 00:29:45 +02:00
|
|
|
ret_val = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
2008-12-16 16:07:55 +02:00
|
|
|
if (ifx_ssc_hwinit(info) < 0)
|
2007-12-21 00:29:45 +02:00
|
|
|
ret_val = -EIO;
|
|
|
|
break;
|
|
|
|
case IFX_SSC_HWOPTS_GET:
|
|
|
|
/* data must be a pointer to a struct ifx_ssc_hwopts */
|
|
|
|
if (from_kernel)
|
2008-12-16 16:07:55 +02:00
|
|
|
memcpy((void *)data, (void *)&info->opts,
|
|
|
|
sizeof(struct ifx_ssc_hwopts));
|
|
|
|
else if (copy_to_user((void *)data,
|
|
|
|
(void *)&info->opts,
|
|
|
|
sizeof(struct ifx_ssc_hwopts)))
|
2007-12-21 00:29:45 +02:00
|
|
|
ret_val = -EFAULT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret_val = -ENOIOCTLCMD;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret_val;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ifx_ssc_ioctl);
|
|
|
|
|
2007-12-22 23:21:38 +02:00
|
|
|
static struct file_operations ifx_ssc_fops = {
|
2008-12-16 16:07:55 +02:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.read = ifx_ssc_read,
|
|
|
|
.write = ifx_ssc_write,
|
|
|
|
.ioctl = ifx_ssc_ioctl,
|
|
|
|
.open = ifx_ssc_open,
|
|
|
|
.release = ifx_ssc_close,
|
2007-12-22 23:21:38 +02:00
|
|
|
};
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
int __init ifx_ssc_init(void)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
struct ifx_ssc_port *info;
|
|
|
|
int i, nbytes;
|
|
|
|
unsigned long flags;
|
|
|
|
int ret_val;
|
|
|
|
|
|
|
|
ret_val = -ENOMEM;
|
|
|
|
nbytes = PORT_CNT * sizeof(struct ifx_ssc_port);
|
2008-12-16 16:07:55 +02:00
|
|
|
isp = kmalloc(nbytes, GFP_KERNEL);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
if (isp == NULL) {
|
2007-12-21 00:29:45 +02:00
|
|
|
printk("%s: no memory for isp\n", __func__);
|
2008-12-16 16:07:55 +02:00
|
|
|
return ret_val;
|
2007-12-21 00:29:45 +02:00
|
|
|
}
|
|
|
|
memset(isp, 0, nbytes);
|
|
|
|
|
|
|
|
ret_val = -ENXIO;
|
2008-12-16 16:07:55 +02:00
|
|
|
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) {
|
2007-12-21 00:29:45 +02:00
|
|
|
goto errout;
|
|
|
|
} else {
|
|
|
|
maj = 0;
|
2008-12-16 16:07:55 +02:00
|
|
|
i = register_chrdev(maj, "ssc", &ifx_ssc_fops);
|
|
|
|
if (i < 0) {
|
|
|
|
printk("Unable to register major %d for the Infineon SSC\n", maj);
|
2007-12-21 00:29:45 +02:00
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (maj == 0)
|
|
|
|
maj = i;
|
|
|
|
|
|
|
|
/* set default values in ifx_ssc_port */
|
|
|
|
for (i = 0; i < PORT_CNT; i++) {
|
|
|
|
info = &isp[i];
|
|
|
|
info->port_nr = i;
|
|
|
|
/* default values for the HwOpts */
|
|
|
|
info->opts.AbortErrDetect = IFX_SSC_DEF_ABRT_ERR_DETECT;
|
|
|
|
info->opts.rxOvErrDetect = IFX_SSC_DEF_RO_ERR_DETECT;
|
|
|
|
info->opts.rxUndErrDetect = IFX_SSC_DEF_RU_ERR_DETECT;
|
|
|
|
info->opts.txOvErrDetect = IFX_SSC_DEF_TO_ERR_DETECT;
|
|
|
|
info->opts.txUndErrDetect = IFX_SSC_DEF_TU_ERR_DETECT;
|
|
|
|
info->opts.loopBack = IFX_SSC_DEF_LOOP_BACK;
|
|
|
|
info->opts.echoMode = IFX_SSC_DEF_ECHO_MODE;
|
|
|
|
info->opts.idleValue = IFX_SSC_DEF_IDLE_DATA;
|
|
|
|
info->opts.clockPolarity = IFX_SSC_DEF_CLOCK_POLARITY;
|
|
|
|
info->opts.clockPhase = IFX_SSC_DEF_CLOCK_PHASE;
|
|
|
|
info->opts.headingControl = IFX_SSC_DEF_HEADING_CONTROL;
|
|
|
|
info->opts.dataWidth = IFX_SSC_DEF_DATA_WIDTH;
|
|
|
|
info->opts.modeRxTx = IFX_SSC_DEF_MODE_RXTX;
|
|
|
|
info->opts.gpoCs = IFX_SSC_DEF_GPO_CS;
|
|
|
|
info->opts.gpoInv = IFX_SSC_DEF_GPO_INV;
|
|
|
|
info->opts.masterSelect = IFX_SSC_DEF_MASTERSLAVE;
|
|
|
|
info->baud = IFX_SSC_DEF_BAUDRATE;
|
|
|
|
info->rxbuf = NULL;
|
|
|
|
info->txbuf = NULL;
|
|
|
|
/* values specific to SSC1 */
|
2008-12-16 16:07:55 +02:00
|
|
|
if (i == 0)
|
2007-12-22 22:22:43 +02:00
|
|
|
info->mapbase = IFXMIPS_SSC_BASE_ADDR;
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32(IFX_SSC_DEF_RMC << IFX_CLC_RUN_DIVIDER_OFFSET, IFXMIPS_SSC_CLC);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
init_waitqueue_head(&info->rwait);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
local_irq_save(flags);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
/* init serial framing register */
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32(IFX_SSC_DEF_SFCON, IFXMIPS_SSC_SFCON);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2007-12-22 23:21:38 +02:00
|
|
|
ret_val = request_irq(IFXMIPS_SSC_TIR, ifx_ssc_tx_int, IRQF_DISABLED, "ifx_ssc_tx", info);
|
2008-12-16 16:07:55 +02:00
|
|
|
if (ret_val) {
|
2007-12-22 23:21:38 +02:00
|
|
|
printk("%s: unable to get irq %d\n", __func__, IFXMIPS_SSC_TIR);
|
2007-12-21 00:29:45 +02:00
|
|
|
local_irq_restore(flags);
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
2007-12-22 23:21:38 +02:00
|
|
|
ret_val = request_irq(IFXMIPS_SSC_RIR, ifx_ssc_rx_int, IRQF_DISABLED, "ifx_ssc_rx", info);
|
2008-12-16 16:07:55 +02:00
|
|
|
if (ret_val) {
|
|
|
|
printk("%s: unable to get irq %d\n", __func__, IFXMIPS_SSC_RIR);
|
|
|
|
local_irq_restore(flags);
|
2007-12-21 00:29:45 +02:00
|
|
|
goto irqerr;
|
|
|
|
}
|
|
|
|
|
2007-12-22 23:21:38 +02:00
|
|
|
ret_val = request_irq(IFXMIPS_SSC_EIR, ifx_ssc_err_int, IRQF_DISABLED, "ifx_ssc_err", info);
|
2008-12-16 16:07:55 +02:00
|
|
|
if (ret_val) {
|
|
|
|
printk("%s: unable to get irq %d\n", __func__, IFXMIPS_SSC_EIR);
|
|
|
|
local_irq_restore(flags);
|
2007-12-21 00:29:45 +02:00
|
|
|
goto irqerr;
|
|
|
|
}
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32(IFX_SSC_DEF_IRNEN, IFXMIPS_SSC_IRN);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
#if 0
|
|
|
|
enable_irq(IFXMIPS_SSC_TIR);
|
|
|
|
enable_irq(IFXMIPS_SSC_RIR);
|
|
|
|
enable_irq(IFXMIPS_SSC_EIR);
|
|
|
|
#endif
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
local_irq_restore(flags);
|
2007-12-21 00:29:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < PORT_CNT; i++) {
|
|
|
|
info = &isp[i];
|
2008-12-16 16:07:55 +02:00
|
|
|
if (ifx_ssc_hwinit(info) < 0) {
|
|
|
|
printk("%s: hardware init failed for port %d\n", __func__, i);
|
2007-12-21 00:29:45 +02:00
|
|
|
goto irqerr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
irqerr:
|
2007-12-22 23:21:38 +02:00
|
|
|
free_irq(IFXMIPS_SSC_TIR, &isp[0]);
|
|
|
|
free_irq(IFXMIPS_SSC_RIR, &isp[0]);
|
|
|
|
free_irq(IFXMIPS_SSC_EIR, &isp[0]);
|
2007-12-21 00:29:45 +02:00
|
|
|
errout:
|
2008-12-16 16:07:55 +02:00
|
|
|
kfree(isp);
|
|
|
|
return ret_val;
|
2007-12-21 00:29:45 +02:00
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
void __exit ifx_ssc_cleanup_module(void)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < PORT_CNT; i++) {
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32(IFX_SSC_WHBSTATE_CLR_ENABLE, IFXMIPS_SSC_WHBSTATE);
|
2007-12-22 23:21:38 +02:00
|
|
|
free_irq(IFXMIPS_SSC_TIR, &isp[i]);
|
|
|
|
free_irq(IFXMIPS_SSC_RIR, &isp[i]);
|
|
|
|
free_irq(IFXMIPS_SSC_EIR, &isp[i]);
|
2007-12-21 00:29:45 +02:00
|
|
|
}
|
2008-12-16 16:07:55 +02:00
|
|
|
kfree(isp);
|
2007-12-21 00:29:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(ifx_ssc_init);
|
|
|
|
module_exit(ifx_ssc_cleanup_module);
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
inline int ifx_ssc_cs_low(u32 pin)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
int ret = 0;
|
2008-12-16 16:07:55 +02:00
|
|
|
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();
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ifx_ssc_cs_low);
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
inline int ifx_ssc_cs_high(u32 pin)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
int ret = 0;
|
2008-12-16 16:07:55 +02:00
|
|
|
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();
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ifx_ssc_cs_high);
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
static int ssc_session(char *tx_buf, u32 tx_len, char *rx_buf, u32 rx_len)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
char *ssc_tx_buf = NULL;
|
|
|
|
char *ssc_rx_buf = NULL;
|
|
|
|
int eff_size = 0;
|
|
|
|
u8 mode = 0;
|
|
|
|
|
|
|
|
if (tx_buf == NULL && tx_len == 0 && rx_buf == NULL && rx_len == 0) {
|
2008-12-16 16:07:55 +02:00
|
|
|
printk("invalid parameters\n");
|
2007-12-21 00:29:45 +02:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto ssc_session_exit;
|
2008-12-16 16:07:55 +02:00
|
|
|
} else if (tx_buf == NULL || tx_len == 0) {
|
2007-12-21 00:29:45 +02:00
|
|
|
if (rx_buf != NULL && rx_len != 0) {
|
|
|
|
mode = IFX_SSC_MODE_RX;
|
2008-12-16 16:07:55 +02:00
|
|
|
} else {
|
|
|
|
printk("invalid parameters\n");
|
2007-12-21 00:29:45 +02:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto ssc_session_exit;
|
|
|
|
}
|
2008-12-16 16:07:55 +02:00
|
|
|
} else if (rx_buf == NULL || rx_len == 0) {
|
|
|
|
if (tx_buf != NULL && tx_len != 0)
|
2007-12-21 00:29:45 +02:00
|
|
|
mode = IFX_SSC_MODE_TX;
|
|
|
|
else {
|
2008-12-16 16:07:55 +02:00
|
|
|
printk("invalid parameters\n");
|
2007-12-21 00:29:45 +02:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto ssc_session_exit;
|
|
|
|
}
|
2008-12-16 16:07:55 +02:00
|
|
|
} else
|
2007-12-21 00:29:45 +02:00
|
|
|
mode = IFX_SSC_MODE_RXTX;
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
if (mode == IFX_SSC_MODE_RXTX)
|
2007-12-21 00:29:45 +02:00
|
|
|
eff_size = tx_len + rx_len;
|
2008-12-16 16:07:55 +02:00
|
|
|
else if (mode == IFX_SSC_MODE_RX)
|
2007-12-21 00:29:45 +02:00
|
|
|
eff_size = rx_len;
|
2008-12-16 16:07:55 +02:00
|
|
|
else
|
2007-12-21 00:29:45 +02:00
|
|
|
eff_size = tx_len;
|
|
|
|
|
2008-12-16 21:39:34 +02:00
|
|
|
/* 4 bytes alignment, required by driver */
|
|
|
|
ssc_tx_buf = kmalloc(sizeof(char) *
|
|
|
|
((eff_size + 3) & (~3)),
|
|
|
|
GFP_ATOMIC);
|
|
|
|
ssc_rx_buf = kmalloc(sizeof(char) *
|
|
|
|
((eff_size + 3) & (~3)),
|
|
|
|
GFP_ATOMIC);
|
2007-12-21 00:29:45 +02:00
|
|
|
if (ssc_tx_buf == NULL || ssc_rx_buf == NULL) {
|
2008-12-16 16:07:55 +02:00
|
|
|
printk("no memory for size of %d\n", eff_size);
|
2007-12-21 00:29:45 +02:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto ssc_session_exit;
|
|
|
|
}
|
2008-12-16 16:07:55 +02:00
|
|
|
memset((void *)ssc_tx_buf, 0, eff_size);
|
|
|
|
memset((void *)ssc_rx_buf, 0, eff_size);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
if (tx_len > 0)
|
|
|
|
memcpy(ssc_tx_buf, tx_buf, tx_len);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
ret = ifx_ssc_kwrite(0, ssc_tx_buf, eff_size);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
if (ret > 0)
|
|
|
|
ssc_tx_buf = NULL; /* should be freed by ifx_ssc_kwrite */
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
if (ret != eff_size) {
|
2008-12-16 16:07:55 +02:00
|
|
|
printk("ifx_ssc_write return %d\n", ret);
|
2007-12-21 00:29:45 +02:00
|
|
|
goto ssc_session_exit;
|
|
|
|
}
|
2008-12-16 16:07:55 +02:00
|
|
|
ret = ifx_ssc_kread(0, ssc_rx_buf, eff_size);
|
2007-12-21 00:29:45 +02:00
|
|
|
if (ret != eff_size) {
|
2008-12-16 16:07:55 +02:00
|
|
|
printk("ifx_ssc_read return %d\n", ret);
|
2007-12-21 00:29:45 +02:00
|
|
|
goto ssc_session_exit;
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
memcpy(rx_buf, ssc_rx_buf + tx_len, rx_len);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
if (mode == IFX_SSC_MODE_TX)
|
2007-12-21 00:29:45 +02:00
|
|
|
ret = tx_len;
|
2008-12-16 16:07:55 +02:00
|
|
|
else
|
2007-12-21 00:29:45 +02:00
|
|
|
ret = rx_len;
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
ssc_session_exit:
|
2007-12-21 00:29:45 +02:00
|
|
|
if (ssc_tx_buf != NULL)
|
2008-12-16 16:07:55 +02:00
|
|
|
kfree(ssc_tx_buf);
|
2007-12-21 00:29:45 +02:00
|
|
|
if (ssc_rx_buf != NULL)
|
2008-12-16 16:07:55 +02:00
|
|
|
kfree(ssc_rx_buf);
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
printk("ssc session fails\n");
|
2007-12-21 00:29:45 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
int ifx_ssc_txrx(char *tx_buf, u32 tx_len, char *rx_buf, u32 rx_len)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
return ssc_session(tx_buf, tx_len, rx_buf, rx_len);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ifx_ssc_txrx);
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
int ifx_ssc_tx(char *tx_buf, u32 tx_len)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
return ssc_session(tx_buf, tx_len, NULL, 0);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ifx_ssc_tx);
|
|
|
|
|
2008-12-16 16:07:55 +02:00
|
|
|
int ifx_ssc_rx(char *rx_buf, u32 rx_len)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
|
|
|
return ssc_session(NULL, 0, rx_buf, rx_len);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ifx_ssc_rx);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
|
2007-12-22 15:55:14 +02:00
|
|
|
MODULE_DESCRIPTION("ifxmips ssc driver");
|
2007-12-21 00:29:45 +02:00
|
|
|
|