V4L/DVB (13751): [Mantis] GPIO_CONTROL: Do not toggle GPIO CW's on HIF operations
[deliverable/linux.git] / drivers / media / dvb / mantis / mantis_hif.c
1 /*
2 Mantis PCI bridge driver
3
4 Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "mantis_common.h"
22 #include "mantis_hif.h"
23 #include "mantis_link.h" /* temporary due to physical layer stuff */
24
25 static int mantis_hif_data_available(struct mantis_ca *ca)
26 {
27 struct mantis_pci *mantis = ca->ca_priv;
28 int rc = 0;
29
30 if (wait_event_interruptible_timeout(ca->hif_data_wq,
31 ca->sbuf_status & MANTIS_SBUF_DATA_AVAIL,
32 msecs_to_jiffies(500)) == -ERESTARTSYS) {
33
34 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Read wait event timeout !", mantis->num);
35 rc = -EREMOTEIO;
36 }
37 ca->sbuf_status &= ~MANTIS_SBUF_DATA_AVAIL;
38 udelay(2);
39 return rc;
40 }
41
42 static int mantis_hif_sbuf_opdone_wait(struct mantis_ca *ca)
43 {
44 struct mantis_pci *mantis = ca->ca_priv;
45 int rc = 0;
46
47 if (wait_event_interruptible_timeout(ca->hif_opdone_wq,
48 ca->hif_event & MANTIS_SBUF_OPDONE,
49 msecs_to_jiffies(500)) == -ERESTARTSYS) {
50
51 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): Smart buffer operation timeout !", mantis->num);
52 rc = -EREMOTEIO;
53 }
54 ca->hif_event &= ~MANTIS_SBUF_OPDONE;
55 udelay(5);
56 return rc;
57 }
58
59
60 int mantis_hif_read_mem(struct mantis_ca *ca, u32 addr)
61 {
62 struct mantis_pci *mantis = ca->ca_priv;
63 u32 hif_addr = 0, data, count = 4;
64
65 dprintk(verbose, MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF Mem Read", mantis->num);
66 hif_addr |= MANTIS_GPIF_HIFRDWRN;
67 hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
68 hif_addr &= ~MANTIS_GPIF_PCMCIAIOM;
69 hif_addr |= addr;
70
71 mmwrite(hif_addr | MANTIS_HIF_STATUS, MANTIS_GPIF_BRADDR);
72 mmwrite(count, MANTIS_GPIF_BRBYTES);
73
74 udelay(20);
75
76 mmwrite(hif_addr, MANTIS_GPIF_ADDR);
77 if (mantis_hif_data_available(ca) != 0) {
78 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): GPIF Smart Buffer burst read failed", mantis->num);
79 return -EREMOTEIO;
80 }
81 if (mantis_hif_sbuf_opdone_wait(ca) != 0) {
82 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): GPIF Smart Buffer operation failed", mantis->num);
83 return -EREMOTEIO;
84 }
85 data = mmread(MANTIS_GPIF_DIN);
86
87 return (data >> 24) & 0xff;
88 }
89
90 int mantis_hif_write_mem(struct mantis_ca *ca, u32 addr, u8 data)
91 {
92 struct mantis_slot *slot = ca->slot;
93 struct mantis_pci *mantis = ca->ca_priv;
94 u32 hif_addr = 0;
95
96 dprintk(verbose, MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF Mem Write", mantis->num);
97 hif_addr &= ~MANTIS_GPIF_HIFRDWRN;
98 hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
99 hif_addr &= ~MANTIS_GPIF_PCMCIAIOM;
100 hif_addr |= addr;
101
102 mmwrite(slot->slave_cfg, MANTIS_GPIF_CFGSLA); /* Slot0 alone for now */
103
104 mmwrite(hif_addr | MANTIS_HIF_STATUS, MANTIS_GPIF_ADDR);
105 mmwrite(data, MANTIS_GPIF_DOUT);
106 ca->hif_job_queue = MANTIS_HIF_MEMWR;
107
108 if (mantis_hif_sbuf_opdone_wait(ca) != 0) {
109 ca->hif_job_queue &= ~MANTIS_HIF_MEMWR;
110 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num);
111 return -EREMOTEIO;
112 }
113 ca->hif_job_queue &= ~MANTIS_HIF_MEMWR;
114 return 0;
115 }
116
117 int mantis_hif_read_iom(struct mantis_ca *ca, u32 addr)
118 {
119 struct mantis_pci *mantis = ca->ca_priv;
120 u32 data, hif_addr = 0;
121
122 dprintk(verbose, MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF I/O Read", mantis->num);
123 hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
124 hif_addr |= MANTIS_GPIF_HIFRDWRN;
125 hif_addr |= MANTIS_GPIF_PCMCIAIOM;
126 hif_addr |= addr;
127
128 mmwrite(hif_addr | MANTIS_HIF_STATUS, MANTIS_GPIF_ADDR);
129 ca->hif_job_queue = MANTIS_HIF_IOMRD;
130
131 if (mantis_hif_sbuf_opdone_wait(ca) != 0) {
132 ca->hif_job_queue &= ~MANTIS_HIF_IOMRD;
133 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num);
134 return -EREMOTEIO;
135 }
136 udelay(50);
137 ca->hif_job_queue &= ~MANTIS_HIF_IOMRD;
138 data = mmread(MANTIS_GPIF_DIN);
139 hif_addr |= MANTIS_GPIF_PCMCIAREG;
140 mmwrite(hif_addr, MANTIS_GPIF_ADDR);
141
142 return data;
143 }
144
145 int mantis_hif_write_iom(struct mantis_ca *ca, u32 addr, u8 data)
146 {
147 struct mantis_pci *mantis = ca->ca_priv;
148 u32 hif_addr = 0;
149
150 dprintk(verbose, MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF I/O Write", mantis->num);
151 hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
152 hif_addr &= ~MANTIS_GPIF_HIFRDWRN;
153 hif_addr |= MANTIS_GPIF_PCMCIAIOM;
154 hif_addr |= addr;
155
156 mmwrite(hif_addr | MANTIS_HIF_STATUS, MANTIS_GPIF_ADDR);
157 mmwrite(data, MANTIS_GPIF_DOUT);
158
159 ca->hif_job_queue = MANTIS_HIF_IOMWR;
160 if (mantis_hif_sbuf_opdone_wait(ca) != 0) {
161 ca->hif_job_queue &= ~MANTIS_HIF_IOMWR;
162 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num);
163 return -EREMOTEIO;
164 }
165 udelay(50);
166 ca->hif_job_queue &= ~MANTIS_HIF_IOMWR;
167 hif_addr |= MANTIS_GPIF_PCMCIAREG;
168 mmwrite(hif_addr, MANTIS_GPIF_ADDR);
169
170 return 0;
171 }
172
173 int mantis_hif_init(struct mantis_ca *ca)
174 {
175 struct mantis_slot *slot = ca->slot;
176 struct mantis_pci *mantis = ca->ca_priv;
177 u32 irqcfg;
178
179 slot[0].slave_cfg = 0x70773028;
180 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Initializing Mantis Host Interface", mantis->num);
181 init_waitqueue_head(&ca->hif_data_wq);
182 init_waitqueue_head(&ca->hif_opdone_wq);
183
184 irqcfg = mmread(MANTIS_GPIF_IRQCFG);
185 irqcfg |= MANTIS_MASK_BRRDY;
186 mmwrite(irqcfg, MANTIS_GPIF_IRQCFG);
187
188 return 0;
189 }
190
191 void mantis_hif_exit(struct mantis_ca *ca)
192 {
193 struct mantis_pci *mantis = ca->ca_priv;
194 u32 irqcfg;
195
196 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Exiting Mantis Host Interface", mantis->num);
197 irqcfg = mmread(MANTIS_GPIF_IRQCFG);
198 irqcfg &= ~MANTIS_MASK_BRRDY;
199 mmwrite(irqcfg, MANTIS_GPIF_IRQCFG);
200 }
This page took 0.036049 seconds and 6 git commands to generate.