2009-12-04 05:41:11 -03:00
# include <linux/kernel.h>
2009-12-04 05:39:57 -03:00
# include <linux/spinlock.h>
2009-12-04 05:41:11 -03:00
# include <asm/irq.h>
# include <linux/signal.h>
# include <linux/sched.h>
# include <linux/interrupt.h>
# include "dmxdev.h"
# include "dvbdev.h"
# include "dvb_demux.h"
# include "dvb_frontend.h"
# include "dvb_net.h"
2009-12-04 05:39:57 -03:00
# include "mantis_common.h"
2009-12-04 05:41:11 -03:00
# include "mantis_reg.h"
# include "mantis_uart.h"
2009-12-04 05:39:57 -03:00
struct mantis_uart_params {
enum mantis_baud baud_rate ;
enum mantis_parity parity ;
} ;
# define UART_MAX_BUF 16
int mantis_uart_read ( struct mantis_pci * mantis , u8 * data )
{
struct mantis_hwconfig * config = mantis - > hwconfig ;
2009-12-15 06:17:54 -03:00
u32 stat = 0 , i ;
2009-12-04 05:39:57 -03:00
/* get data */
for ( i = 0 ; i < ( config - > bytes + 1 ) ; i + + ) {
2009-12-15 06:17:54 -03:00
stat = mmread ( MANTIS_UART_STAT ) ;
2009-12-04 05:39:57 -03:00
if ( stat & MANTIS_UART_RXFIFO_FULL ) {
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_ERROR , 1 , " RX Fifo FULL " ) ;
2009-12-04 05:39:57 -03:00
}
data [ i ] = mmread ( MANTIS_UART_RXD ) & 0x3f ;
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_DEBUG , 1 , " Reading ... <%02x> " , data [ i ] & 0x3f ) ;
2009-12-04 05:39:57 -03:00
if ( data [ i ] & ( 1 < < 7 ) ) {
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_ERROR , 1 , " UART framing error " ) ;
2009-12-04 05:39:57 -03:00
return - EINVAL ;
}
if ( data [ i ] & ( 1 < < 6 ) ) {
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_ERROR , 1 , " UART parity error " ) ;
2009-12-04 05:39:57 -03:00
return - EINVAL ;
}
}
return 0 ;
}
static void mantis_uart_work ( struct work_struct * work )
{
struct mantis_pci * mantis = container_of ( work , struct mantis_pci , uart_work ) ;
struct mantis_hwconfig * config = mantis - > hwconfig ;
u8 buf [ 16 ] ;
int i ;
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_DEBUG , 1 , " UART read " ) ;
2009-12-04 05:39:57 -03:00
mantis_uart_read ( mantis , buf ) ;
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_DEBUG , 1 , " UART: " ) ;
2009-12-04 05:39:57 -03:00
for ( i = 0 ; i < ( config - > bytes + 1 ) ; i + + )
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_DEBUG , 0 , " <%02x> " , buf [ i ] ) ;
2009-12-04 05:39:57 -03:00
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_DEBUG , 0 , " \n " ) ;
2009-12-04 05:39:57 -03:00
}
static int mantis_uart_setup ( struct mantis_pci * mantis ,
struct mantis_uart_params * params )
{
char * rates [ ] = { " B_9600 " , " B_19200 " , " B_38400 " , " B_57600 " , " B_115200 " } ;
char * parity [ ] = { " NONE " , " ODD " , " EVEN " } ;
u32 reg ;
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_DEBUG , 1 , " Set Parity <%s> Baud Rate <%s> " ,
2009-12-04 05:39:57 -03:00
parity [ params - > parity ] ,
rates [ params - > baud_rate ] ) ;
mmwrite ( ( mmread ( MANTIS_UART_CTL ) | ( params - > parity & 0x3 ) ) , MANTIS_UART_CTL ) ;
reg = mmread ( MANTIS_UART_BAUD ) ;
switch ( params - > baud_rate ) {
case MANTIS_BAUD_9600 :
reg | = 0xd8 ;
break ;
case MANTIS_BAUD_19200 :
reg | = 0x6c ;
break ;
case MANTIS_BAUD_38400 :
reg | = 0x36 ;
break ;
case MANTIS_BAUD_57600 :
reg | = 0x23 ;
break ;
case MANTIS_BAUD_115200 :
reg | = 0x11 ;
break ;
default :
return - EINVAL ;
}
mmwrite ( reg , MANTIS_UART_BAUD ) ;
return 0 ;
}
int mantis_uart_init ( struct mantis_pci * mantis )
{
struct mantis_hwconfig * config = mantis - > hwconfig ;
struct mantis_uart_params params ;
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_DEBUG , 1 , " Initializing UART .. " ) ;
2009-12-04 05:39:57 -03:00
/* default parity: */
params . baud_rate = config - > baud_rate ;
params . parity = config - > parity ;
init_waitqueue_head ( & mantis - > uart_wq ) ;
spin_lock_init ( & mantis - > uart_lock ) ;
INIT_WORK ( & mantis - > uart_work , mantis_uart_work ) ;
/* disable interrupt */
mmwrite ( mmread ( MANTIS_UART_CTL ) & 0xffef , MANTIS_UART_CTL ) ;
mantis_uart_setup ( mantis , & params ) ;
/* default 1 byte */
mmwrite ( ( mmread ( MANTIS_UART_BAUD ) | ( config - > bytes < < 8 ) ) , MANTIS_UART_BAUD ) ;
/* flush buffer */
mmwrite ( ( mmread ( MANTIS_UART_CTL ) | MANTIS_UART_RXFLUSH ) , MANTIS_UART_CTL ) ;
/* enable interrupt */
mmwrite ( mmread ( MANTIS_INT_MASK ) | 0x800 , MANTIS_INT_MASK ) ;
mmwrite ( mmread ( MANTIS_UART_CTL ) | MANTIS_UART_RXINT , MANTIS_UART_CTL ) ;
schedule_work ( & mantis - > uart_work ) ;
return 0 ;
}
2009-12-04 05:41:11 -03:00
EXPORT_SYMBOL_GPL ( mantis_uart_init ) ;
2009-12-04 05:39:57 -03:00
void mantis_uart_exit ( struct mantis_pci * mantis )
{
/* disable interrupt */
mmwrite ( mmread ( MANTIS_UART_CTL ) & 0xffef , MANTIS_UART_CTL ) ;
}
2009-12-04 05:41:11 -03:00
EXPORT_SYMBOL_GPL ( mantis_uart_exit ) ;