Path: blob/master/drivers/media/dvb/mantis/mantis_hif.c
15112 views
/*1Mantis PCI bridge driver23Copyright (C) Manu Abraham ([email protected])45This program is free software; you can redistribute it and/or modify6it under the terms of the GNU General Public License as published by7the Free Software Foundation; either version 2 of the License, or8(at your option) any later version.910This program is distributed in the hope that it will be useful,11but WITHOUT ANY WARRANTY; without even the implied warranty of12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13GNU General Public License for more details.1415You should have received a copy of the GNU General Public License16along with this program; if not, write to the Free Software17Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.18*/1920#include <linux/kernel.h>21#include <linux/signal.h>22#include <linux/sched.h>2324#include <linux/interrupt.h>2526#include "dmxdev.h"27#include "dvbdev.h"28#include "dvb_demux.h"29#include "dvb_frontend.h"30#include "dvb_net.h"3132#include "mantis_common.h"3334#include "mantis_hif.h"35#include "mantis_link.h" /* temporary due to physical layer stuff */3637#include "mantis_reg.h"383940static int mantis_hif_sbuf_opdone_wait(struct mantis_ca *ca)41{42struct mantis_pci *mantis = ca->ca_priv;43int rc = 0;4445if (wait_event_timeout(ca->hif_opdone_wq,46ca->hif_event & MANTIS_SBUF_OPDONE,47msecs_to_jiffies(500)) == -ERESTARTSYS) {4849dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): Smart buffer operation timeout !", mantis->num);50rc = -EREMOTEIO;51}52dprintk(MANTIS_DEBUG, 1, "Smart Buffer Operation complete");53ca->hif_event &= ~MANTIS_SBUF_OPDONE;54return rc;55}5657static int mantis_hif_write_wait(struct mantis_ca *ca)58{59struct mantis_pci *mantis = ca->ca_priv;60u32 opdone = 0, timeout = 0;61int rc = 0;6263if (wait_event_timeout(ca->hif_write_wq,64mantis->gpif_status & MANTIS_GPIF_WRACK,65msecs_to_jiffies(500)) == -ERESTARTSYS) {6667dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): Write ACK timed out !", mantis->num);68rc = -EREMOTEIO;69}70dprintk(MANTIS_DEBUG, 1, "Write Acknowledged");71mantis->gpif_status &= ~MANTIS_GPIF_WRACK;72while (!opdone) {73opdone = (mmread(MANTIS_GPIF_STATUS) & MANTIS_SBUF_OPDONE);74udelay(500);75timeout++;76if (timeout > 100) {77dprintk(MANTIS_ERROR, 1, "Adater(%d) Slot(0): Write operation timed out!", mantis->num);78rc = -ETIMEDOUT;79break;80}81}82dprintk(MANTIS_DEBUG, 1, "HIF Write success");83return rc;84}858687int mantis_hif_read_mem(struct mantis_ca *ca, u32 addr)88{89struct mantis_pci *mantis = ca->ca_priv;90u32 hif_addr = 0, data, count = 4;9192dprintk(MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF Mem Read", mantis->num);93mutex_lock(&ca->ca_lock);94hif_addr &= ~MANTIS_GPIF_PCMCIAREG;95hif_addr &= ~MANTIS_GPIF_PCMCIAIOM;96hif_addr |= MANTIS_HIF_STATUS;97hif_addr |= addr;9899mmwrite(hif_addr, MANTIS_GPIF_BRADDR);100mmwrite(count, MANTIS_GPIF_BRBYTES);101udelay(20);102mmwrite(hif_addr | MANTIS_GPIF_HIFRDWRN, MANTIS_GPIF_ADDR);103104if (mantis_hif_sbuf_opdone_wait(ca) != 0) {105dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): GPIF Smart Buffer operation failed", mantis->num);106mutex_unlock(&ca->ca_lock);107return -EREMOTEIO;108}109data = mmread(MANTIS_GPIF_DIN);110mutex_unlock(&ca->ca_lock);111dprintk(MANTIS_DEBUG, 1, "Mem Read: 0x%02x", data);112return (data >> 24) & 0xff;113}114115int mantis_hif_write_mem(struct mantis_ca *ca, u32 addr, u8 data)116{117struct mantis_slot *slot = ca->slot;118struct mantis_pci *mantis = ca->ca_priv;119u32 hif_addr = 0;120121dprintk(MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF Mem Write", mantis->num);122mutex_lock(&ca->ca_lock);123hif_addr &= ~MANTIS_GPIF_HIFRDWRN;124hif_addr &= ~MANTIS_GPIF_PCMCIAREG;125hif_addr &= ~MANTIS_GPIF_PCMCIAIOM;126hif_addr |= MANTIS_HIF_STATUS;127hif_addr |= addr;128129mmwrite(slot->slave_cfg, MANTIS_GPIF_CFGSLA); /* Slot0 alone for now */130mmwrite(hif_addr, MANTIS_GPIF_ADDR);131mmwrite(data, MANTIS_GPIF_DOUT);132133if (mantis_hif_write_wait(ca) != 0) {134dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num);135mutex_unlock(&ca->ca_lock);136return -EREMOTEIO;137}138dprintk(MANTIS_DEBUG, 1, "Mem Write: (0x%02x to 0x%02x)", data, addr);139mutex_unlock(&ca->ca_lock);140141return 0;142}143144int mantis_hif_read_iom(struct mantis_ca *ca, u32 addr)145{146struct mantis_pci *mantis = ca->ca_priv;147u32 data, hif_addr = 0;148149dprintk(MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF I/O Read", mantis->num);150mutex_lock(&ca->ca_lock);151hif_addr &= ~MANTIS_GPIF_PCMCIAREG;152hif_addr |= MANTIS_GPIF_PCMCIAIOM;153hif_addr |= MANTIS_HIF_STATUS;154hif_addr |= addr;155156mmwrite(hif_addr, MANTIS_GPIF_BRADDR);157mmwrite(1, MANTIS_GPIF_BRBYTES);158udelay(20);159mmwrite(hif_addr | MANTIS_GPIF_HIFRDWRN, MANTIS_GPIF_ADDR);160161if (mantis_hif_sbuf_opdone_wait(ca) != 0) {162dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num);163mutex_unlock(&ca->ca_lock);164return -EREMOTEIO;165}166data = mmread(MANTIS_GPIF_DIN);167dprintk(MANTIS_DEBUG, 1, "I/O Read: 0x%02x", data);168udelay(50);169mutex_unlock(&ca->ca_lock);170171return (u8) data;172}173174int mantis_hif_write_iom(struct mantis_ca *ca, u32 addr, u8 data)175{176struct mantis_pci *mantis = ca->ca_priv;177u32 hif_addr = 0;178179dprintk(MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF I/O Write", mantis->num);180mutex_lock(&ca->ca_lock);181hif_addr &= ~MANTIS_GPIF_PCMCIAREG;182hif_addr &= ~MANTIS_GPIF_HIFRDWRN;183hif_addr |= MANTIS_GPIF_PCMCIAIOM;184hif_addr |= MANTIS_HIF_STATUS;185hif_addr |= addr;186187mmwrite(hif_addr, MANTIS_GPIF_ADDR);188mmwrite(data, MANTIS_GPIF_DOUT);189190if (mantis_hif_write_wait(ca) != 0) {191dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num);192mutex_unlock(&ca->ca_lock);193return -EREMOTEIO;194}195dprintk(MANTIS_DEBUG, 1, "I/O Write: (0x%02x to 0x%02x)", data, addr);196mutex_unlock(&ca->ca_lock);197udelay(50);198199return 0;200}201202int mantis_hif_init(struct mantis_ca *ca)203{204struct mantis_slot *slot = ca->slot;205struct mantis_pci *mantis = ca->ca_priv;206u32 irqcfg;207208slot[0].slave_cfg = 0x70773028;209dprintk(MANTIS_ERROR, 1, "Adapter(%d) Initializing Mantis Host Interface", mantis->num);210211mutex_lock(&ca->ca_lock);212irqcfg = mmread(MANTIS_GPIF_IRQCFG);213irqcfg = MANTIS_MASK_BRRDY |214MANTIS_MASK_WRACK |215MANTIS_MASK_EXTIRQ |216MANTIS_MASK_WSTO |217MANTIS_MASK_OTHERR |218MANTIS_MASK_OVFLW;219220mmwrite(irqcfg, MANTIS_GPIF_IRQCFG);221mutex_unlock(&ca->ca_lock);222223return 0;224}225226void mantis_hif_exit(struct mantis_ca *ca)227{228struct mantis_pci *mantis = ca->ca_priv;229u32 irqcfg;230231dprintk(MANTIS_ERROR, 1, "Adapter(%d) Exiting Mantis Host Interface", mantis->num);232mutex_lock(&ca->ca_lock);233irqcfg = mmread(MANTIS_GPIF_IRQCFG);234irqcfg &= ~MANTIS_MASK_BRRDY;235mmwrite(irqcfg, MANTIS_GPIF_IRQCFG);236mutex_unlock(&ca->ca_lock);237}238239240