2009-12-04 05:09:47 -03:00
/*
Mantis PCI bridge driver
2009-12-15 09:13:49 -03:00
Copyright ( C ) Manu Abraham ( abraham . manu @ gmail . com )
2009-12-04 05:09:47 -03: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 . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
2009-12-04 05:41:11 -03:00
# include <linux/kernel.h>
# include <linux/signal.h>
# include <linux/sched.h>
# include <linux/interrupt.h>
2011-06-16 11:01:34 +00:00
# include <asm/io.h>
2009-12-04 05:41:11 -03:00
2017-12-28 13:03:51 -05:00
# include <media/dmxdev.h>
# include <media/dvbdev.h>
# include <media/dvb_demux.h>
# include <media/dvb_frontend.h>
# include <media/dvb_net.h>
2009-12-04 05:41:11 -03:00
2009-12-04 05:09:47 -03:00
# include "mantis_common.h"
2009-12-04 05:41:11 -03:00
2009-12-04 05:09:47 -03:00
# include "mantis_hif.h"
# include "mantis_link.h" /* temporary due to physical layer stuff */
2009-12-04 05:41:11 -03:00
# include "mantis_reg.h"
2009-12-04 05:09:47 -03:00
static int mantis_hif_sbuf_opdone_wait ( struct mantis_ca * ca )
{
struct mantis_pci * mantis = ca - > ca_priv ;
int rc = 0 ;
2009-12-04 05:29:25 -03:00
if ( wait_event_timeout ( ca - > hif_opdone_wq ,
ca - > hif_event & MANTIS_SBUF_OPDONE ,
msecs_to_jiffies ( 500 ) ) = = - ERESTARTSYS ) {
2009-12-04 05:09:47 -03:00
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_ERROR , 1 , " Adapter(%d) Slot(0): Smart buffer operation timeout ! " , mantis - > num ) ;
2009-12-04 05:09:47 -03:00
rc = - EREMOTEIO ;
}
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_DEBUG , 1 , " Smart Buffer Operation complete " ) ;
2009-12-04 05:09:47 -03:00
ca - > hif_event & = ~ MANTIS_SBUF_OPDONE ;
return rc ;
}
2009-12-04 05:29:48 -03:00
static int mantis_hif_write_wait ( struct mantis_ca * ca )
{
struct mantis_pci * mantis = ca - > ca_priv ;
u32 opdone = 0 , timeout = 0 ;
int rc = 0 ;
if ( wait_event_timeout ( ca - > hif_write_wq ,
mantis - > gpif_status & MANTIS_GPIF_WRACK ,
msecs_to_jiffies ( 500 ) ) = = - ERESTARTSYS ) {
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_ERROR , 1 , " Adapter(%d) Slot(0): Write ACK timed out ! " , mantis - > num ) ;
2009-12-04 05:29:48 -03:00
rc = - EREMOTEIO ;
}
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_DEBUG , 1 , " Write Acknowledged " ) ;
2009-12-04 05:29:48 -03:00
mantis - > gpif_status & = ~ MANTIS_GPIF_WRACK ;
while ( ! opdone ) {
opdone = ( mmread ( MANTIS_GPIF_STATUS ) & MANTIS_SBUF_OPDONE ) ;
udelay ( 500 ) ;
timeout + + ;
if ( timeout > 100 ) {
2012-02-08 07:28:23 -03:00
dprintk ( MANTIS_ERROR , 1 , " Adapter(%d) Slot(0): Write operation timed out! " , mantis - > num ) ;
2009-12-04 05:29:48 -03:00
rc = - ETIMEDOUT ;
break ;
}
}
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_DEBUG , 1 , " HIF Write success " ) ;
2009-12-04 05:29:48 -03:00
return rc ;
}
2009-12-04 05:16:24 -03:00
2009-12-04 05:09:47 -03:00
int mantis_hif_read_mem ( struct mantis_ca * ca , u32 addr )
{
struct mantis_pci * mantis = ca - > ca_priv ;
u32 hif_addr = 0 , data , count = 4 ;
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_DEBUG , 1 , " Adapter(%d) Slot(0): Request HIF Mem Read " , mantis - > num ) ;
2009-12-04 05:34:19 -03:00
mutex_lock ( & ca - > ca_lock ) ;
2009-12-04 05:09:47 -03:00
hif_addr & = ~ MANTIS_GPIF_PCMCIAREG ;
hif_addr & = ~ MANTIS_GPIF_PCMCIAIOM ;
2009-12-04 05:31:21 -03:00
hif_addr | = MANTIS_HIF_STATUS ;
2009-12-04 05:09:47 -03:00
hif_addr | = addr ;
2009-12-04 05:31:21 -03:00
mmwrite ( hif_addr , MANTIS_GPIF_BRADDR ) ;
2009-12-04 05:09:47 -03:00
mmwrite ( count , MANTIS_GPIF_BRBYTES ) ;
udelay ( 20 ) ;
2009-12-04 05:31:21 -03:00
mmwrite ( hif_addr | MANTIS_GPIF_HIFRDWRN , MANTIS_GPIF_ADDR ) ;
2009-12-04 05:09:47 -03:00
if ( mantis_hif_sbuf_opdone_wait ( ca ) ! = 0 ) {
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_ERROR , 1 , " Adapter(%d) Slot(0): GPIF Smart Buffer operation failed " , mantis - > num ) ;
2009-12-04 05:34:19 -03:00
mutex_unlock ( & ca - > ca_lock ) ;
2009-12-04 05:09:47 -03:00
return - EREMOTEIO ;
}
2009-12-04 05:13:21 -03:00
data = mmread ( MANTIS_GPIF_DIN ) ;
2009-12-04 05:34:19 -03:00
mutex_unlock ( & ca - > ca_lock ) ;
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_DEBUG , 1 , " Mem Read: 0x%02x " , data ) ;
2009-12-04 05:09:47 -03:00
return ( data > > 24 ) & 0xff ;
}
int mantis_hif_write_mem ( struct mantis_ca * ca , u32 addr , u8 data )
{
struct mantis_slot * slot = ca - > slot ;
struct mantis_pci * mantis = ca - > ca_priv ;
u32 hif_addr = 0 ;
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_DEBUG , 1 , " Adapter(%d) Slot(0): Request HIF Mem Write " , mantis - > num ) ;
2009-12-04 05:34:19 -03:00
mutex_lock ( & ca - > ca_lock ) ;
2009-12-04 05:09:47 -03:00
hif_addr & = ~ MANTIS_GPIF_HIFRDWRN ;
hif_addr & = ~ MANTIS_GPIF_PCMCIAREG ;
hif_addr & = ~ MANTIS_GPIF_PCMCIAIOM ;
2009-12-04 05:31:21 -03:00
hif_addr | = MANTIS_HIF_STATUS ;
hif_addr | = addr ;
2009-12-04 05:09:47 -03:00
mmwrite ( slot - > slave_cfg , MANTIS_GPIF_CFGSLA ) ; /* Slot0 alone for now */
2009-12-04 05:31:21 -03:00
mmwrite ( hif_addr , MANTIS_GPIF_ADDR ) ;
2009-12-04 05:13:21 -03:00
mmwrite ( data , MANTIS_GPIF_DOUT ) ;
2009-12-04 05:09:47 -03:00
2009-12-04 05:29:48 -03:00
if ( mantis_hif_write_wait ( ca ) ! = 0 ) {
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_ERROR , 1 , " Adapter(%d) Slot(0): HIF Smart Buffer operation failed " , mantis - > num ) ;
2009-12-04 05:34:19 -03:00
mutex_unlock ( & ca - > ca_lock ) ;
2009-12-04 05:09:47 -03:00
return - EREMOTEIO ;
}
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_DEBUG , 1 , " Mem Write: (0x%02x to 0x%02x) " , data , addr ) ;
2009-12-04 05:34:19 -03:00
mutex_unlock ( & ca - > ca_lock ) ;
2009-12-04 05:23:38 -03:00
2009-12-04 05:09:47 -03:00
return 0 ;
}
2009-12-04 05:11:14 -03:00
int mantis_hif_read_iom ( struct mantis_ca * ca , u32 addr )
2009-12-04 05:10:25 -03:00
{
struct mantis_pci * mantis = ca - > ca_priv ;
2009-12-04 05:11:14 -03:00
u32 data , hif_addr = 0 ;
2009-12-04 05:10:25 -03:00
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_DEBUG , 1 , " Adapter(%d) Slot(0): Request HIF I/O Read " , mantis - > num ) ;
2009-12-04 05:34:19 -03:00
mutex_lock ( & ca - > ca_lock ) ;
2009-12-04 05:10:25 -03:00
hif_addr & = ~ MANTIS_GPIF_PCMCIAREG ;
hif_addr | = MANTIS_GPIF_PCMCIAIOM ;
2009-12-04 05:31:21 -03:00
hif_addr | = MANTIS_HIF_STATUS ;
2009-12-04 05:10:25 -03:00
hif_addr | = addr ;
2009-12-04 05:31:21 -03:00
mmwrite ( hif_addr , MANTIS_GPIF_BRADDR ) ;
2009-12-04 05:30:59 -03:00
mmwrite ( 1 , MANTIS_GPIF_BRBYTES ) ;
udelay ( 20 ) ;
2009-12-04 05:31:21 -03:00
mmwrite ( hif_addr | MANTIS_GPIF_HIFRDWRN , MANTIS_GPIF_ADDR ) ;
2009-12-04 05:10:25 -03:00
if ( mantis_hif_sbuf_opdone_wait ( ca ) ! = 0 ) {
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_ERROR , 1 , " Adapter(%d) Slot(0): HIF Smart Buffer operation failed " , mantis - > num ) ;
2009-12-04 05:34:19 -03:00
mutex_unlock ( & ca - > ca_lock ) ;
2009-12-04 05:10:25 -03:00
return - EREMOTEIO ;
}
2009-12-04 05:13:21 -03:00
data = mmread ( MANTIS_GPIF_DIN ) ;
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_DEBUG , 1 , " I/O Read: 0x%02x " , data ) ;
2009-12-04 05:22:57 -03:00
udelay ( 50 ) ;
2009-12-04 05:34:19 -03:00
mutex_unlock ( & ca - > ca_lock ) ;
2009-12-04 05:10:25 -03:00
2009-12-04 05:21:05 -03:00
return ( u8 ) data ;
2009-12-04 05:10:25 -03:00
}
2009-12-04 05:11:14 -03:00
int mantis_hif_write_iom ( struct mantis_ca * ca , u32 addr , u8 data )
2009-12-04 05:10:25 -03:00
{
struct mantis_pci * mantis = ca - > ca_priv ;
u32 hif_addr = 0 ;
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_DEBUG , 1 , " Adapter(%d) Slot(0): Request HIF I/O Write " , mantis - > num ) ;
2009-12-04 05:34:19 -03:00
mutex_lock ( & ca - > ca_lock ) ;
2009-12-04 05:10:25 -03:00
hif_addr & = ~ MANTIS_GPIF_PCMCIAREG ;
hif_addr & = ~ MANTIS_GPIF_HIFRDWRN ;
hif_addr | = MANTIS_GPIF_PCMCIAIOM ;
2009-12-04 05:31:21 -03:00
hif_addr | = MANTIS_HIF_STATUS ;
2009-12-04 05:10:25 -03:00
hif_addr | = addr ;
2009-12-04 05:31:21 -03:00
mmwrite ( hif_addr , MANTIS_GPIF_ADDR ) ;
2009-12-04 05:13:21 -03:00
mmwrite ( data , MANTIS_GPIF_DOUT ) ;
2009-12-04 05:10:25 -03:00
2009-12-04 05:29:48 -03:00
if ( mantis_hif_write_wait ( ca ) ! = 0 ) {
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_ERROR , 1 , " Adapter(%d) Slot(0): HIF Smart Buffer operation failed " , mantis - > num ) ;
2009-12-04 05:34:19 -03:00
mutex_unlock ( & ca - > ca_lock ) ;
2009-12-04 05:10:25 -03:00
return - EREMOTEIO ;
}
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_DEBUG , 1 , " I/O Write: (0x%02x to 0x%02x) " , data , addr ) ;
2009-12-04 05:34:19 -03:00
mutex_unlock ( & ca - > ca_lock ) ;
2009-12-04 05:22:57 -03:00
udelay ( 50 ) ;
2009-12-04 05:10:25 -03:00
return 0 ;
}
2009-12-04 05:09:47 -03:00
int mantis_hif_init ( struct mantis_ca * ca )
{
2009-12-04 05:15:10 -03:00
struct mantis_slot * slot = ca - > slot ;
2009-12-04 05:09:47 -03:00
struct mantis_pci * mantis = ca - > ca_priv ;
u32 irqcfg ;
2009-12-04 05:15:10 -03:00
slot [ 0 ] . slave_cfg = 0x70773028 ;
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_ERROR , 1 , " Adapter(%d) Initializing Mantis Host Interface " , mantis - > num ) ;
2009-12-04 05:09:47 -03:00
2009-12-04 05:34:19 -03:00
mutex_lock ( & ca - > ca_lock ) ;
2009-12-04 05:27:53 -03:00
irqcfg = mmread ( MANTIS_GPIF_IRQCFG ) ;
irqcfg = MANTIS_MASK_BRRDY |
MANTIS_MASK_WRACK |
MANTIS_MASK_EXTIRQ |
MANTIS_MASK_WSTO |
MANTIS_MASK_OTHERR |
MANTIS_MASK_OVFLW ;
2009-12-04 05:09:47 -03:00
mmwrite ( irqcfg , MANTIS_GPIF_IRQCFG ) ;
2009-12-04 05:34:19 -03:00
mutex_unlock ( & ca - > ca_lock ) ;
2009-12-04 05:09:47 -03:00
return 0 ;
}
void mantis_hif_exit ( struct mantis_ca * ca )
{
struct mantis_pci * mantis = ca - > ca_priv ;
u32 irqcfg ;
2009-12-04 05:41:11 -03:00
dprintk ( MANTIS_ERROR , 1 , " Adapter(%d) Exiting Mantis Host Interface " , mantis - > num ) ;
2009-12-04 05:34:19 -03:00
mutex_lock ( & ca - > ca_lock ) ;
2009-12-04 05:09:47 -03:00
irqcfg = mmread ( MANTIS_GPIF_IRQCFG ) ;
irqcfg & = ~ MANTIS_MASK_BRRDY ;
mmwrite ( irqcfg , MANTIS_GPIF_IRQCFG ) ;
2009-12-04 05:34:19 -03:00
mutex_unlock ( & ca - > ca_lock ) ;
2009-12-04 05:09:47 -03:00
}