Commit 276e49a01a7e6c4a7bfb78618cf2f5befbf9f5de

Authored by Oliver Endriss
Committed by Mauro Carvalho Chehab
1 parent c471b331dd

V4L/DVB (5987): saa7146: clean-up irq processing

Interrupt processing fixed: First handle interrupt, then acknowledge it.
Otherwise the same interrupt might occur twice.
Cleaned-up i2c interrupt handler and i2c error messages.

Signed-off-by: Oliver Endriss <o.endriss@gmx.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>

Showing 2 changed files with 29 additions and 23 deletions Inline Diff

drivers/media/common/saa7146_core.c
1 /* 1 /*
2 saa7146.o - driver for generic saa7146-based hardware 2 saa7146.o - driver for generic saa7146-based hardware
3 3
4 Copyright (C) 1998-2003 Michael Hunold <michael@mihu.de> 4 Copyright (C) 1998-2003 Michael Hunold <michael@mihu.de>
5 5
6 This program is free software; you can redistribute it and/or modify 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 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 8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License 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 17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */ 19 */
20 20
21 #include <media/saa7146.h> 21 #include <media/saa7146.h>
22 22
23 LIST_HEAD(saa7146_devices); 23 LIST_HEAD(saa7146_devices);
24 DEFINE_MUTEX(saa7146_devices_lock); 24 DEFINE_MUTEX(saa7146_devices_lock);
25 25
26 static int saa7146_num; 26 static int saa7146_num;
27 27
28 unsigned int saa7146_debug; 28 unsigned int saa7146_debug;
29 29
30 module_param(saa7146_debug, uint, 0644); 30 module_param(saa7146_debug, uint, 0644);
31 MODULE_PARM_DESC(saa7146_debug, "debug level (default: 0)"); 31 MODULE_PARM_DESC(saa7146_debug, "debug level (default: 0)");
32 32
33 #if 0 33 #if 0
34 static void dump_registers(struct saa7146_dev* dev) 34 static void dump_registers(struct saa7146_dev* dev)
35 { 35 {
36 int i = 0; 36 int i = 0;
37 37
38 INFO((" @ %li jiffies:\n",jiffies)); 38 INFO((" @ %li jiffies:\n",jiffies));
39 for(i = 0; i <= 0x148; i+=4) { 39 for(i = 0; i <= 0x148; i+=4) {
40 printk("0x%03x: 0x%08x\n",i,saa7146_read(dev,i)); 40 printk("0x%03x: 0x%08x\n",i,saa7146_read(dev,i));
41 } 41 }
42 } 42 }
43 #endif 43 #endif
44 44
45 /**************************************************************************** 45 /****************************************************************************
46 * gpio and debi helper functions 46 * gpio and debi helper functions
47 ****************************************************************************/ 47 ****************************************************************************/
48 48
49 void saa7146_setgpio(struct saa7146_dev *dev, int port, u32 data) 49 void saa7146_setgpio(struct saa7146_dev *dev, int port, u32 data)
50 { 50 {
51 u32 value = 0; 51 u32 value = 0;
52 52
53 BUG_ON(port > 3); 53 BUG_ON(port > 3);
54 54
55 value = saa7146_read(dev, GPIO_CTRL); 55 value = saa7146_read(dev, GPIO_CTRL);
56 value &= ~(0xff << (8*port)); 56 value &= ~(0xff << (8*port));
57 value |= (data << (8*port)); 57 value |= (data << (8*port));
58 saa7146_write(dev, GPIO_CTRL, value); 58 saa7146_write(dev, GPIO_CTRL, value);
59 } 59 }
60 60
61 /* This DEBI code is based on the saa7146 Stradis driver by Nathan Laredo */ 61 /* This DEBI code is based on the saa7146 Stradis driver by Nathan Laredo */
62 int saa7146_wait_for_debi_done(struct saa7146_dev *dev, int nobusyloop) 62 int saa7146_wait_for_debi_done(struct saa7146_dev *dev, int nobusyloop)
63 { 63 {
64 unsigned long start; 64 unsigned long start;
65 int err; 65 int err;
66 66
67 /* wait for registers to be programmed */ 67 /* wait for registers to be programmed */
68 start = jiffies; 68 start = jiffies;
69 while (1) { 69 while (1) {
70 err = time_after(jiffies, start + HZ/20); 70 err = time_after(jiffies, start + HZ/20);
71 if (saa7146_read(dev, MC2) & 2) 71 if (saa7146_read(dev, MC2) & 2)
72 break; 72 break;
73 if (err) { 73 if (err) {
74 DEB_S(("timed out while waiting for registers getting programmed\n")); 74 DEB_S(("timed out while waiting for registers getting programmed\n"));
75 return -ETIMEDOUT; 75 return -ETIMEDOUT;
76 } 76 }
77 if (nobusyloop) 77 if (nobusyloop)
78 msleep(1); 78 msleep(1);
79 } 79 }
80 80
81 /* wait for transfer to complete */ 81 /* wait for transfer to complete */
82 start = jiffies; 82 start = jiffies;
83 while (1) { 83 while (1) {
84 err = time_after(jiffies, start + HZ/4); 84 err = time_after(jiffies, start + HZ/4);
85 if (!(saa7146_read(dev, PSR) & SPCI_DEBI_S)) 85 if (!(saa7146_read(dev, PSR) & SPCI_DEBI_S))
86 break; 86 break;
87 saa7146_read(dev, MC2); 87 saa7146_read(dev, MC2);
88 if (err) { 88 if (err) {
89 DEB_S(("timed out while waiting for transfer completion\n")); 89 DEB_S(("timed out while waiting for transfer completion\n"));
90 return -ETIMEDOUT; 90 return -ETIMEDOUT;
91 } 91 }
92 if (nobusyloop) 92 if (nobusyloop)
93 msleep(1); 93 msleep(1);
94 } 94 }
95 95
96 return 0; 96 return 0;
97 } 97 }
98 98
99 /**************************************************************************** 99 /****************************************************************************
100 * general helper functions 100 * general helper functions
101 ****************************************************************************/ 101 ****************************************************************************/
102 102
103 /* this is videobuf_vmalloc_to_sg() from video-buf.c 103 /* this is videobuf_vmalloc_to_sg() from video-buf.c
104 make sure virt has been allocated with vmalloc_32(), otherwise the BUG() 104 make sure virt has been allocated with vmalloc_32(), otherwise the BUG()
105 may be triggered on highmem machines */ 105 may be triggered on highmem machines */
106 static struct scatterlist* vmalloc_to_sg(unsigned char *virt, int nr_pages) 106 static struct scatterlist* vmalloc_to_sg(unsigned char *virt, int nr_pages)
107 { 107 {
108 struct scatterlist *sglist; 108 struct scatterlist *sglist;
109 struct page *pg; 109 struct page *pg;
110 int i; 110 int i;
111 111
112 sglist = kcalloc(nr_pages, sizeof(struct scatterlist), GFP_KERNEL); 112 sglist = kcalloc(nr_pages, sizeof(struct scatterlist), GFP_KERNEL);
113 if (NULL == sglist) 113 if (NULL == sglist)
114 return NULL; 114 return NULL;
115 for (i = 0; i < nr_pages; i++, virt += PAGE_SIZE) { 115 for (i = 0; i < nr_pages; i++, virt += PAGE_SIZE) {
116 pg = vmalloc_to_page(virt); 116 pg = vmalloc_to_page(virt);
117 if (NULL == pg) 117 if (NULL == pg)
118 goto err; 118 goto err;
119 BUG_ON(PageHighMem(pg)); 119 BUG_ON(PageHighMem(pg));
120 sglist[i].page = pg; 120 sglist[i].page = pg;
121 sglist[i].length = PAGE_SIZE; 121 sglist[i].length = PAGE_SIZE;
122 } 122 }
123 return sglist; 123 return sglist;
124 124
125 err: 125 err:
126 kfree(sglist); 126 kfree(sglist);
127 return NULL; 127 return NULL;
128 } 128 }
129 129
130 /********************************************************************************/ 130 /********************************************************************************/
131 /* common page table functions */ 131 /* common page table functions */
132 132
133 void *saa7146_vmalloc_build_pgtable(struct pci_dev *pci, long length, struct saa7146_pgtable *pt) 133 void *saa7146_vmalloc_build_pgtable(struct pci_dev *pci, long length, struct saa7146_pgtable *pt)
134 { 134 {
135 int pages = (length+PAGE_SIZE-1)/PAGE_SIZE; 135 int pages = (length+PAGE_SIZE-1)/PAGE_SIZE;
136 void *mem = vmalloc_32(length); 136 void *mem = vmalloc_32(length);
137 int slen = 0; 137 int slen = 0;
138 138
139 if (NULL == mem) 139 if (NULL == mem)
140 goto err_null; 140 goto err_null;
141 141
142 if (!(pt->slist = vmalloc_to_sg(mem, pages))) 142 if (!(pt->slist = vmalloc_to_sg(mem, pages)))
143 goto err_free_mem; 143 goto err_free_mem;
144 144
145 if (saa7146_pgtable_alloc(pci, pt)) 145 if (saa7146_pgtable_alloc(pci, pt))
146 goto err_free_slist; 146 goto err_free_slist;
147 147
148 pt->nents = pages; 148 pt->nents = pages;
149 slen = pci_map_sg(pci,pt->slist,pt->nents,PCI_DMA_FROMDEVICE); 149 slen = pci_map_sg(pci,pt->slist,pt->nents,PCI_DMA_FROMDEVICE);
150 if (0 == slen) 150 if (0 == slen)
151 goto err_free_pgtable; 151 goto err_free_pgtable;
152 152
153 if (0 != saa7146_pgtable_build_single(pci, pt, pt->slist, slen)) 153 if (0 != saa7146_pgtable_build_single(pci, pt, pt->slist, slen))
154 goto err_unmap_sg; 154 goto err_unmap_sg;
155 155
156 return mem; 156 return mem;
157 157
158 err_unmap_sg: 158 err_unmap_sg:
159 pci_unmap_sg(pci, pt->slist, pt->nents, PCI_DMA_FROMDEVICE); 159 pci_unmap_sg(pci, pt->slist, pt->nents, PCI_DMA_FROMDEVICE);
160 err_free_pgtable: 160 err_free_pgtable:
161 saa7146_pgtable_free(pci, pt); 161 saa7146_pgtable_free(pci, pt);
162 err_free_slist: 162 err_free_slist:
163 kfree(pt->slist); 163 kfree(pt->slist);
164 pt->slist = NULL; 164 pt->slist = NULL;
165 err_free_mem: 165 err_free_mem:
166 vfree(mem); 166 vfree(mem);
167 err_null: 167 err_null:
168 return NULL; 168 return NULL;
169 } 169 }
170 170
171 void saa7146_vfree_destroy_pgtable(struct pci_dev *pci, void *mem, struct saa7146_pgtable *pt) 171 void saa7146_vfree_destroy_pgtable(struct pci_dev *pci, void *mem, struct saa7146_pgtable *pt)
172 { 172 {
173 pci_unmap_sg(pci, pt->slist, pt->nents, PCI_DMA_FROMDEVICE); 173 pci_unmap_sg(pci, pt->slist, pt->nents, PCI_DMA_FROMDEVICE);
174 saa7146_pgtable_free(pci, pt); 174 saa7146_pgtable_free(pci, pt);
175 kfree(pt->slist); 175 kfree(pt->slist);
176 pt->slist = NULL; 176 pt->slist = NULL;
177 vfree(mem); 177 vfree(mem);
178 } 178 }
179 179
180 void saa7146_pgtable_free(struct pci_dev *pci, struct saa7146_pgtable *pt) 180 void saa7146_pgtable_free(struct pci_dev *pci, struct saa7146_pgtable *pt)
181 { 181 {
182 if (NULL == pt->cpu) 182 if (NULL == pt->cpu)
183 return; 183 return;
184 pci_free_consistent(pci, pt->size, pt->cpu, pt->dma); 184 pci_free_consistent(pci, pt->size, pt->cpu, pt->dma);
185 pt->cpu = NULL; 185 pt->cpu = NULL;
186 } 186 }
187 187
188 int saa7146_pgtable_alloc(struct pci_dev *pci, struct saa7146_pgtable *pt) 188 int saa7146_pgtable_alloc(struct pci_dev *pci, struct saa7146_pgtable *pt)
189 { 189 {
190 u32 *cpu; 190 u32 *cpu;
191 dma_addr_t dma_addr; 191 dma_addr_t dma_addr;
192 192
193 cpu = pci_alloc_consistent(pci, PAGE_SIZE, &dma_addr); 193 cpu = pci_alloc_consistent(pci, PAGE_SIZE, &dma_addr);
194 if (NULL == cpu) { 194 if (NULL == cpu) {
195 return -ENOMEM; 195 return -ENOMEM;
196 } 196 }
197 pt->size = PAGE_SIZE; 197 pt->size = PAGE_SIZE;
198 pt->cpu = cpu; 198 pt->cpu = cpu;
199 pt->dma = dma_addr; 199 pt->dma = dma_addr;
200 200
201 return 0; 201 return 0;
202 } 202 }
203 203
204 int saa7146_pgtable_build_single(struct pci_dev *pci, struct saa7146_pgtable *pt, 204 int saa7146_pgtable_build_single(struct pci_dev *pci, struct saa7146_pgtable *pt,
205 struct scatterlist *list, int sglen ) 205 struct scatterlist *list, int sglen )
206 { 206 {
207 u32 *ptr, fill; 207 u32 *ptr, fill;
208 int nr_pages = 0; 208 int nr_pages = 0;
209 int i,p; 209 int i,p;
210 210
211 BUG_ON(0 == sglen); 211 BUG_ON(0 == sglen);
212 BUG_ON(list->offset > PAGE_SIZE); 212 BUG_ON(list->offset > PAGE_SIZE);
213 213
214 /* if we have a user buffer, the first page may not be 214 /* if we have a user buffer, the first page may not be
215 aligned to a page boundary. */ 215 aligned to a page boundary. */
216 pt->offset = list->offset; 216 pt->offset = list->offset;
217 217
218 ptr = pt->cpu; 218 ptr = pt->cpu;
219 for (i = 0; i < sglen; i++, list++) { 219 for (i = 0; i < sglen; i++, list++) {
220 /* 220 /*
221 printk("i:%d, adr:0x%08x, len:%d, offset:%d\n", i,sg_dma_address(list), sg_dma_len(list), list->offset); 221 printk("i:%d, adr:0x%08x, len:%d, offset:%d\n", i,sg_dma_address(list), sg_dma_len(list), list->offset);
222 */ 222 */
223 for (p = 0; p * 4096 < list->length; p++, ptr++) { 223 for (p = 0; p * 4096 < list->length; p++, ptr++) {
224 *ptr = cpu_to_le32(sg_dma_address(list) + p * 4096); 224 *ptr = cpu_to_le32(sg_dma_address(list) + p * 4096);
225 nr_pages++; 225 nr_pages++;
226 } 226 }
227 } 227 }
228 228
229 229
230 /* safety; fill the page table up with the last valid page */ 230 /* safety; fill the page table up with the last valid page */
231 fill = *(ptr-1); 231 fill = *(ptr-1);
232 for(i=nr_pages;i<1024;i++) { 232 for(i=nr_pages;i<1024;i++) {
233 *ptr++ = fill; 233 *ptr++ = fill;
234 } 234 }
235 235
236 /* 236 /*
237 ptr = pt->cpu; 237 ptr = pt->cpu;
238 printk("offset: %d\n",pt->offset); 238 printk("offset: %d\n",pt->offset);
239 for(i=0;i<5;i++) { 239 for(i=0;i<5;i++) {
240 printk("ptr1 %d: 0x%08x\n",i,ptr[i]); 240 printk("ptr1 %d: 0x%08x\n",i,ptr[i]);
241 } 241 }
242 */ 242 */
243 return 0; 243 return 0;
244 } 244 }
245 245
246 /********************************************************************************/ 246 /********************************************************************************/
247 /* interrupt handler */ 247 /* interrupt handler */
248 static irqreturn_t interrupt_hw(int irq, void *dev_id) 248 static irqreturn_t interrupt_hw(int irq, void *dev_id)
249 { 249 {
250 struct saa7146_dev *dev = dev_id; 250 struct saa7146_dev *dev = dev_id;
251 u32 isr = 0; 251 u32 isr;
252 u32 ack_isr;
252 253
253 /* read out the interrupt status register */ 254 /* read out the interrupt status register */
254 isr = saa7146_read(dev, ISR); 255 ack_isr = isr = saa7146_read(dev, ISR);
255 256
256 /* is this our interrupt? */ 257 /* is this our interrupt? */
257 if ( 0 == isr ) { 258 if ( 0 == isr ) {
258 /* nope, some other device */ 259 /* nope, some other device */
259 return IRQ_NONE; 260 return IRQ_NONE;
260 } 261 }
261 262
262 saa7146_write(dev, ISR, isr);
263
264 if( 0 != (dev->ext)) { 263 if( 0 != (dev->ext)) {
265 if( 0 != (dev->ext->irq_mask & isr )) { 264 if( 0 != (dev->ext->irq_mask & isr )) {
266 if( 0 != dev->ext->irq_func ) { 265 if( 0 != dev->ext->irq_func ) {
267 dev->ext->irq_func(dev, &isr); 266 dev->ext->irq_func(dev, &isr);
268 } 267 }
269 isr &= ~dev->ext->irq_mask; 268 isr &= ~dev->ext->irq_mask;
270 } 269 }
271 } 270 }
272 if (0 != (isr & (MASK_27))) { 271 if (0 != (isr & (MASK_27))) {
273 DEB_INT(("irq: RPS0 (0x%08x).\n",isr)); 272 DEB_INT(("irq: RPS0 (0x%08x).\n",isr));
274 if( 0 != dev->vv_data && 0 != dev->vv_callback) { 273 if( 0 != dev->vv_data && 0 != dev->vv_callback) {
275 dev->vv_callback(dev,isr); 274 dev->vv_callback(dev,isr);
276 } 275 }
277 isr &= ~MASK_27; 276 isr &= ~MASK_27;
278 } 277 }
279 if (0 != (isr & (MASK_28))) { 278 if (0 != (isr & (MASK_28))) {
280 if( 0 != dev->vv_data && 0 != dev->vv_callback) { 279 if( 0 != dev->vv_data && 0 != dev->vv_callback) {
281 dev->vv_callback(dev,isr); 280 dev->vv_callback(dev,isr);
282 } 281 }
283 isr &= ~MASK_28; 282 isr &= ~MASK_28;
284 } 283 }
285 if (0 != (isr & (MASK_16|MASK_17))) { 284 if (0 != (isr & (MASK_16|MASK_17))) {
286 u32 status = saa7146_read(dev, I2C_STATUS); 285 SAA7146_IER_DISABLE(dev, MASK_16|MASK_17);
287 if( (0x3 == (status & 0x3)) || (0 == (status & 0x1)) ) { 286 /* only wake up if we expect something */
288 SAA7146_IER_DISABLE(dev, MASK_16|MASK_17); 287 if (0 != dev->i2c_op) {
289 /* only wake up if we expect something */ 288 dev->i2c_op = 0;
290 if( 0 != dev->i2c_op ) { 289 wake_up(&dev->i2c_wq);
291 u32 psr = (saa7146_read(dev, PSR) >> 16) & 0x2;
292 u32 ssr = (saa7146_read(dev, SSR) >> 17) & 0x1f;
293 DEB_I2C(("irq: i2c, status: 0x%08x, psr:0x%02x, ssr:0x%02x).\n",status,psr,ssr));
294 dev->i2c_op = 0;
295 wake_up(&dev->i2c_wq);
296 } else {
297 DEB_I2C(("unexpected irq: i2c, status: 0x%08x, isr %#x\n",status, isr));
298 }
299 } else { 290 } else {
300 DEB_I2C(("unhandled irq: i2c, status: 0x%08x, isr %#x\n",status, isr)); 291 u32 psr = saa7146_read(dev, PSR);
292 u32 ssr = saa7146_read(dev, SSR);
293 printk(KERN_WARNING "%s: unexpected i2c irq: isr %08x psr %08x ssr %08x\n",
294 dev->name, isr, psr, ssr);
301 } 295 }
302 isr &= ~(MASK_16|MASK_17); 296 isr &= ~(MASK_16|MASK_17);
303 } 297 }
304 if( 0 != isr ) { 298 if( 0 != isr ) {
305 ERR(("warning: interrupt enabled, but not handled properly.(0x%08x)\n",isr)); 299 ERR(("warning: interrupt enabled, but not handled properly.(0x%08x)\n",isr));
306 ERR(("disabling interrupt source(s)!\n")); 300 ERR(("disabling interrupt source(s)!\n"));
307 SAA7146_IER_DISABLE(dev,isr); 301 SAA7146_IER_DISABLE(dev,isr);
308 } 302 }
303 saa7146_write(dev, ISR, ack_isr);
309 return IRQ_HANDLED; 304 return IRQ_HANDLED;
310 } 305 }
311 306
312 /*********************************************************************************/ 307 /*********************************************************************************/
313 /* configuration-functions */ 308 /* configuration-functions */
314 309
315 static int saa7146_init_one(struct pci_dev *pci, const struct pci_device_id *ent) 310 static int saa7146_init_one(struct pci_dev *pci, const struct pci_device_id *ent)
316 { 311 {
317 struct saa7146_pci_extension_data *pci_ext = (struct saa7146_pci_extension_data *)ent->driver_data; 312 struct saa7146_pci_extension_data *pci_ext = (struct saa7146_pci_extension_data *)ent->driver_data;
318 struct saa7146_extension *ext = pci_ext->ext; 313 struct saa7146_extension *ext = pci_ext->ext;
319 struct saa7146_dev *dev; 314 struct saa7146_dev *dev;
320 int err = -ENOMEM; 315 int err = -ENOMEM;
321 316
322 /* clear out mem for sure */ 317 /* clear out mem for sure */
323 dev = kzalloc(sizeof(struct saa7146_dev), GFP_KERNEL); 318 dev = kzalloc(sizeof(struct saa7146_dev), GFP_KERNEL);
324 if (!dev) { 319 if (!dev) {
325 ERR(("out of memory.\n")); 320 ERR(("out of memory.\n"));
326 goto out; 321 goto out;
327 } 322 }
328 323
329 DEB_EE(("pci:%p\n",pci)); 324 DEB_EE(("pci:%p\n",pci));
330 325
331 err = pci_enable_device(pci); 326 err = pci_enable_device(pci);
332 if (err < 0) { 327 if (err < 0) {
333 ERR(("pci_enable_device() failed.\n")); 328 ERR(("pci_enable_device() failed.\n"));
334 goto err_free; 329 goto err_free;
335 } 330 }
336 331
337 /* enable bus-mastering */ 332 /* enable bus-mastering */
338 pci_set_master(pci); 333 pci_set_master(pci);
339 334
340 dev->pci = pci; 335 dev->pci = pci;
341 336
342 /* get chip-revision; this is needed to enable bug-fixes */ 337 /* get chip-revision; this is needed to enable bug-fixes */
343 err = pci_read_config_dword(pci, PCI_CLASS_REVISION, &dev->revision); 338 err = pci_read_config_dword(pci, PCI_CLASS_REVISION, &dev->revision);
344 if (err < 0) { 339 if (err < 0) {
345 ERR(("pci_read_config_dword() failed.\n")); 340 ERR(("pci_read_config_dword() failed.\n"));
346 goto err_disable; 341 goto err_disable;
347 } 342 }
348 dev->revision &= 0xf; 343 dev->revision &= 0xf;
349 344
350 /* remap the memory from virtual to physical adress */ 345 /* remap the memory from virtual to physical adress */
351 346
352 err = pci_request_region(pci, 0, "saa7146"); 347 err = pci_request_region(pci, 0, "saa7146");
353 if (err < 0) 348 if (err < 0)
354 goto err_disable; 349 goto err_disable;
355 350
356 dev->mem = ioremap(pci_resource_start(pci, 0), 351 dev->mem = ioremap(pci_resource_start(pci, 0),
357 pci_resource_len(pci, 0)); 352 pci_resource_len(pci, 0));
358 if (!dev->mem) { 353 if (!dev->mem) {
359 ERR(("ioremap() failed.\n")); 354 ERR(("ioremap() failed.\n"));
360 err = -ENODEV; 355 err = -ENODEV;
361 goto err_release; 356 goto err_release;
362 } 357 }
363 358
364 /* we don't do a master reset here anymore, it screws up 359 /* we don't do a master reset here anymore, it screws up
365 some boards that don't have an i2c-eeprom for configuration 360 some boards that don't have an i2c-eeprom for configuration
366 values */ 361 values */
367 /* 362 /*
368 saa7146_write(dev, MC1, MASK_31); 363 saa7146_write(dev, MC1, MASK_31);
369 */ 364 */
370 365
371 /* disable all irqs */ 366 /* disable all irqs */
372 saa7146_write(dev, IER, 0); 367 saa7146_write(dev, IER, 0);
373 368
374 /* shut down all dma transfers and rps tasks */ 369 /* shut down all dma transfers and rps tasks */
375 saa7146_write(dev, MC1, 0x30ff0000); 370 saa7146_write(dev, MC1, 0x30ff0000);
376 371
377 /* clear out any rps-signals pending */ 372 /* clear out any rps-signals pending */
378 saa7146_write(dev, MC2, 0xf8000000); 373 saa7146_write(dev, MC2, 0xf8000000);
379 374
380 /* request an interrupt for the saa7146 */ 375 /* request an interrupt for the saa7146 */
381 err = request_irq(pci->irq, interrupt_hw, IRQF_SHARED | IRQF_DISABLED, 376 err = request_irq(pci->irq, interrupt_hw, IRQF_SHARED | IRQF_DISABLED,
382 dev->name, dev); 377 dev->name, dev);
383 if (err < 0) { 378 if (err < 0) {
384 ERR(("request_irq() failed.\n")); 379 ERR(("request_irq() failed.\n"));
385 goto err_unmap; 380 goto err_unmap;
386 } 381 }
387 382
388 err = -ENOMEM; 383 err = -ENOMEM;
389 384
390 /* get memory for various stuff */ 385 /* get memory for various stuff */
391 dev->d_rps0.cpu_addr = pci_alloc_consistent(pci, SAA7146_RPS_MEM, 386 dev->d_rps0.cpu_addr = pci_alloc_consistent(pci, SAA7146_RPS_MEM,
392 &dev->d_rps0.dma_handle); 387 &dev->d_rps0.dma_handle);
393 if (!dev->d_rps0.cpu_addr) 388 if (!dev->d_rps0.cpu_addr)
394 goto err_free_irq; 389 goto err_free_irq;
395 memset(dev->d_rps0.cpu_addr, 0x0, SAA7146_RPS_MEM); 390 memset(dev->d_rps0.cpu_addr, 0x0, SAA7146_RPS_MEM);
396 391
397 dev->d_rps1.cpu_addr = pci_alloc_consistent(pci, SAA7146_RPS_MEM, 392 dev->d_rps1.cpu_addr = pci_alloc_consistent(pci, SAA7146_RPS_MEM,
398 &dev->d_rps1.dma_handle); 393 &dev->d_rps1.dma_handle);
399 if (!dev->d_rps1.cpu_addr) 394 if (!dev->d_rps1.cpu_addr)
400 goto err_free_rps0; 395 goto err_free_rps0;
401 memset(dev->d_rps1.cpu_addr, 0x0, SAA7146_RPS_MEM); 396 memset(dev->d_rps1.cpu_addr, 0x0, SAA7146_RPS_MEM);
402 397
403 dev->d_i2c.cpu_addr = pci_alloc_consistent(pci, SAA7146_RPS_MEM, 398 dev->d_i2c.cpu_addr = pci_alloc_consistent(pci, SAA7146_RPS_MEM,
404 &dev->d_i2c.dma_handle); 399 &dev->d_i2c.dma_handle);
405 if (!dev->d_i2c.cpu_addr) 400 if (!dev->d_i2c.cpu_addr)
406 goto err_free_rps1; 401 goto err_free_rps1;
407 memset(dev->d_i2c.cpu_addr, 0x0, SAA7146_RPS_MEM); 402 memset(dev->d_i2c.cpu_addr, 0x0, SAA7146_RPS_MEM);
408 403
409 /* the rest + print status message */ 404 /* the rest + print status message */
410 405
411 /* create a nice device name */ 406 /* create a nice device name */
412 sprintf(dev->name, "saa7146 (%d)", saa7146_num); 407 sprintf(dev->name, "saa7146 (%d)", saa7146_num);
413 408
414 INFO(("found saa7146 @ mem %p (revision %d, irq %d) (0x%04x,0x%04x).\n", dev->mem, dev->revision, pci->irq, pci->subsystem_vendor, pci->subsystem_device)); 409 INFO(("found saa7146 @ mem %p (revision %d, irq %d) (0x%04x,0x%04x).\n", dev->mem, dev->revision, pci->irq, pci->subsystem_vendor, pci->subsystem_device));
415 dev->ext = ext; 410 dev->ext = ext;
416 411
417 pci_set_drvdata(pci, dev); 412 pci_set_drvdata(pci, dev);
418 413
419 mutex_init(&dev->lock); 414 mutex_init(&dev->lock);
420 spin_lock_init(&dev->int_slock); 415 spin_lock_init(&dev->int_slock);
421 spin_lock_init(&dev->slock); 416 spin_lock_init(&dev->slock);
422 417
423 mutex_init(&dev->i2c_lock); 418 mutex_init(&dev->i2c_lock);
424 419
425 dev->module = THIS_MODULE; 420 dev->module = THIS_MODULE;
426 init_waitqueue_head(&dev->i2c_wq); 421 init_waitqueue_head(&dev->i2c_wq);
427 422
428 /* set some sane pci arbitrition values */ 423 /* set some sane pci arbitrition values */
429 saa7146_write(dev, PCI_BT_V1, 0x1c00101f); 424 saa7146_write(dev, PCI_BT_V1, 0x1c00101f);
430 425
431 /* TODO: use the status code of the callback */ 426 /* TODO: use the status code of the callback */
432 427
433 err = -ENODEV; 428 err = -ENODEV;
434 429
435 if (ext->probe && ext->probe(dev)) { 430 if (ext->probe && ext->probe(dev)) {
436 DEB_D(("ext->probe() failed for %p. skipping device.\n",dev)); 431 DEB_D(("ext->probe() failed for %p. skipping device.\n",dev));
437 goto err_free_i2c; 432 goto err_free_i2c;
438 } 433 }
439 434
440 if (ext->attach(dev, pci_ext)) { 435 if (ext->attach(dev, pci_ext)) {
441 DEB_D(("ext->attach() failed for %p. skipping device.\n",dev)); 436 DEB_D(("ext->attach() failed for %p. skipping device.\n",dev));
442 goto err_unprobe; 437 goto err_unprobe;
443 } 438 }
444 439
445 INIT_LIST_HEAD(&dev->item); 440 INIT_LIST_HEAD(&dev->item);
446 list_add_tail(&dev->item,&saa7146_devices); 441 list_add_tail(&dev->item,&saa7146_devices);
447 saa7146_num++; 442 saa7146_num++;
448 443
449 err = 0; 444 err = 0;
450 out: 445 out:
451 return err; 446 return err;
452 447
453 err_unprobe: 448 err_unprobe:
454 pci_set_drvdata(pci, NULL); 449 pci_set_drvdata(pci, NULL);
455 err_free_i2c: 450 err_free_i2c:
456 pci_free_consistent(pci, SAA7146_RPS_MEM, dev->d_i2c.cpu_addr, 451 pci_free_consistent(pci, SAA7146_RPS_MEM, dev->d_i2c.cpu_addr,
457 dev->d_i2c.dma_handle); 452 dev->d_i2c.dma_handle);
458 err_free_rps1: 453 err_free_rps1:
459 pci_free_consistent(pci, SAA7146_RPS_MEM, dev->d_rps1.cpu_addr, 454 pci_free_consistent(pci, SAA7146_RPS_MEM, dev->d_rps1.cpu_addr,
460 dev->d_rps1.dma_handle); 455 dev->d_rps1.dma_handle);
461 err_free_rps0: 456 err_free_rps0:
462 pci_free_consistent(pci, SAA7146_RPS_MEM, dev->d_rps0.cpu_addr, 457 pci_free_consistent(pci, SAA7146_RPS_MEM, dev->d_rps0.cpu_addr,
463 dev->d_rps0.dma_handle); 458 dev->d_rps0.dma_handle);
464 err_free_irq: 459 err_free_irq:
465 free_irq(pci->irq, (void *)dev); 460 free_irq(pci->irq, (void *)dev);
466 err_unmap: 461 err_unmap:
467 iounmap(dev->mem); 462 iounmap(dev->mem);
468 err_release: 463 err_release:
469 pci_release_region(pci, 0); 464 pci_release_region(pci, 0);
470 err_disable: 465 err_disable:
471 pci_disable_device(pci); 466 pci_disable_device(pci);
472 err_free: 467 err_free:
473 kfree(dev); 468 kfree(dev);
474 goto out; 469 goto out;
475 } 470 }
476 471
477 static void saa7146_remove_one(struct pci_dev *pdev) 472 static void saa7146_remove_one(struct pci_dev *pdev)
478 { 473 {
479 struct saa7146_dev* dev = pci_get_drvdata(pdev); 474 struct saa7146_dev* dev = pci_get_drvdata(pdev);
480 struct { 475 struct {
481 void *addr; 476 void *addr;
482 dma_addr_t dma; 477 dma_addr_t dma;
483 } dev_map[] = { 478 } dev_map[] = {
484 { dev->d_i2c.cpu_addr, dev->d_i2c.dma_handle }, 479 { dev->d_i2c.cpu_addr, dev->d_i2c.dma_handle },
485 { dev->d_rps1.cpu_addr, dev->d_rps1.dma_handle }, 480 { dev->d_rps1.cpu_addr, dev->d_rps1.dma_handle },
486 { dev->d_rps0.cpu_addr, dev->d_rps0.dma_handle }, 481 { dev->d_rps0.cpu_addr, dev->d_rps0.dma_handle },
487 { NULL, 0 } 482 { NULL, 0 }
488 }, *p; 483 }, *p;
489 484
490 DEB_EE(("dev:%p\n",dev)); 485 DEB_EE(("dev:%p\n",dev));
491 486
492 dev->ext->detach(dev); 487 dev->ext->detach(dev);
493 488
494 /* shut down all video dma transfers */ 489 /* shut down all video dma transfers */
495 saa7146_write(dev, MC1, 0x00ff0000); 490 saa7146_write(dev, MC1, 0x00ff0000);
496 491
497 /* disable all irqs, release irq-routine */ 492 /* disable all irqs, release irq-routine */
498 saa7146_write(dev, IER, 0); 493 saa7146_write(dev, IER, 0);
499 494
500 free_irq(pdev->irq, dev); 495 free_irq(pdev->irq, dev);
501 496
502 for (p = dev_map; p->addr; p++) 497 for (p = dev_map; p->addr; p++)
503 pci_free_consistent(pdev, SAA7146_RPS_MEM, p->addr, p->dma); 498 pci_free_consistent(pdev, SAA7146_RPS_MEM, p->addr, p->dma);
504 499
505 iounmap(dev->mem); 500 iounmap(dev->mem);
506 pci_release_region(pdev, 0); 501 pci_release_region(pdev, 0);
507 list_del(&dev->item); 502 list_del(&dev->item);
508 pci_disable_device(pdev); 503 pci_disable_device(pdev);
509 kfree(dev); 504 kfree(dev);
510 505
511 saa7146_num--; 506 saa7146_num--;
512 } 507 }
513 508
514 /*********************************************************************************/ 509 /*********************************************************************************/
515 /* extension handling functions */ 510 /* extension handling functions */
516 511
517 int saa7146_register_extension(struct saa7146_extension* ext) 512 int saa7146_register_extension(struct saa7146_extension* ext)
518 { 513 {
519 DEB_EE(("ext:%p\n",ext)); 514 DEB_EE(("ext:%p\n",ext));
520 515
521 ext->driver.name = ext->name; 516 ext->driver.name = ext->name;
522 ext->driver.id_table = ext->pci_tbl; 517 ext->driver.id_table = ext->pci_tbl;
523 ext->driver.probe = saa7146_init_one; 518 ext->driver.probe = saa7146_init_one;
524 ext->driver.remove = saa7146_remove_one; 519 ext->driver.remove = saa7146_remove_one;
525 520
526 printk("saa7146: register extension '%s'.\n",ext->name); 521 printk("saa7146: register extension '%s'.\n",ext->name);
527 return pci_register_driver(&ext->driver); 522 return pci_register_driver(&ext->driver);
528 } 523 }
529 524
530 int saa7146_unregister_extension(struct saa7146_extension* ext) 525 int saa7146_unregister_extension(struct saa7146_extension* ext)
531 { 526 {
532 DEB_EE(("ext:%p\n",ext)); 527 DEB_EE(("ext:%p\n",ext));
533 printk("saa7146: unregister extension '%s'.\n",ext->name); 528 printk("saa7146: unregister extension '%s'.\n",ext->name);
534 pci_unregister_driver(&ext->driver); 529 pci_unregister_driver(&ext->driver);
535 return 0; 530 return 0;
536 } 531 }
537 532
538 EXPORT_SYMBOL_GPL(saa7146_register_extension); 533 EXPORT_SYMBOL_GPL(saa7146_register_extension);
539 EXPORT_SYMBOL_GPL(saa7146_unregister_extension); 534 EXPORT_SYMBOL_GPL(saa7146_unregister_extension);
540 535
541 /* misc functions used by extension modules */ 536 /* misc functions used by extension modules */
542 EXPORT_SYMBOL_GPL(saa7146_pgtable_alloc); 537 EXPORT_SYMBOL_GPL(saa7146_pgtable_alloc);
543 EXPORT_SYMBOL_GPL(saa7146_pgtable_free); 538 EXPORT_SYMBOL_GPL(saa7146_pgtable_free);
544 EXPORT_SYMBOL_GPL(saa7146_pgtable_build_single); 539 EXPORT_SYMBOL_GPL(saa7146_pgtable_build_single);
545 EXPORT_SYMBOL_GPL(saa7146_vmalloc_build_pgtable); 540 EXPORT_SYMBOL_GPL(saa7146_vmalloc_build_pgtable);
546 EXPORT_SYMBOL_GPL(saa7146_vfree_destroy_pgtable); 541 EXPORT_SYMBOL_GPL(saa7146_vfree_destroy_pgtable);
547 EXPORT_SYMBOL_GPL(saa7146_wait_for_debi_done); 542 EXPORT_SYMBOL_GPL(saa7146_wait_for_debi_done);
548 543
549 EXPORT_SYMBOL_GPL(saa7146_setgpio); 544 EXPORT_SYMBOL_GPL(saa7146_setgpio);
550 545
551 EXPORT_SYMBOL_GPL(saa7146_i2c_adapter_prepare); 546 EXPORT_SYMBOL_GPL(saa7146_i2c_adapter_prepare);
552 547
553 EXPORT_SYMBOL_GPL(saa7146_debug); 548 EXPORT_SYMBOL_GPL(saa7146_debug);
554 EXPORT_SYMBOL_GPL(saa7146_devices); 549 EXPORT_SYMBOL_GPL(saa7146_devices);
555 EXPORT_SYMBOL_GPL(saa7146_devices_lock); 550 EXPORT_SYMBOL_GPL(saa7146_devices_lock);
drivers/media/common/saa7146_i2c.c
1 #include <media/saa7146_vv.h> 1 #include <media/saa7146_vv.h>
2 2
3 static u32 saa7146_i2c_func(struct i2c_adapter *adapter) 3 static u32 saa7146_i2c_func(struct i2c_adapter *adapter)
4 { 4 {
5 //fm DEB_I2C(("'%s'.\n", adapter->name)); 5 //fm DEB_I2C(("'%s'.\n", adapter->name));
6 6
7 return I2C_FUNC_I2C 7 return I2C_FUNC_I2C
8 | I2C_FUNC_SMBUS_QUICK 8 | I2C_FUNC_SMBUS_QUICK
9 | I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE 9 | I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE
10 | I2C_FUNC_SMBUS_READ_BYTE_DATA | I2C_FUNC_SMBUS_WRITE_BYTE_DATA; 10 | I2C_FUNC_SMBUS_READ_BYTE_DATA | I2C_FUNC_SMBUS_WRITE_BYTE_DATA;
11 } 11 }
12 12
13 /* this function returns the status-register of our i2c-device */ 13 /* this function returns the status-register of our i2c-device */
14 static inline u32 saa7146_i2c_status(struct saa7146_dev *dev) 14 static inline u32 saa7146_i2c_status(struct saa7146_dev *dev)
15 { 15 {
16 u32 iicsta = saa7146_read(dev, I2C_STATUS); 16 u32 iicsta = saa7146_read(dev, I2C_STATUS);
17 /* 17 /*
18 DEB_I2C(("status: 0x%08x\n",iicsta)); 18 DEB_I2C(("status: 0x%08x\n",iicsta));
19 */ 19 */
20 return iicsta; 20 return iicsta;
21 } 21 }
22 22
23 /* this function runs through the i2c-messages and prepares the data to be 23 /* this function runs through the i2c-messages and prepares the data to be
24 sent through the saa7146. have a look at the specifications p. 122 ff 24 sent through the saa7146. have a look at the specifications p. 122 ff
25 to understand this. it returns the number of u32s to send, or -1 25 to understand this. it returns the number of u32s to send, or -1
26 in case of an error. */ 26 in case of an error. */
27 static int saa7146_i2c_msg_prepare(const struct i2c_msg *m, int num, u32 *op) 27 static int saa7146_i2c_msg_prepare(const struct i2c_msg *m, int num, u32 *op)
28 { 28 {
29 int h1, h2; 29 int h1, h2;
30 int i, j, addr; 30 int i, j, addr;
31 int mem = 0, op_count = 0; 31 int mem = 0, op_count = 0;
32 32
33 /* first determine size of needed memory */ 33 /* first determine size of needed memory */
34 for(i = 0; i < num; i++) { 34 for(i = 0; i < num; i++) {
35 mem += m[i].len + 1; 35 mem += m[i].len + 1;
36 } 36 }
37 37
38 /* worst case: we need one u32 for three bytes to be send 38 /* worst case: we need one u32 for three bytes to be send
39 plus one extra byte to address the device */ 39 plus one extra byte to address the device */
40 mem = 1 + ((mem-1) / 3); 40 mem = 1 + ((mem-1) / 3);
41 41
42 /* we assume that op points to a memory of at least SAA7146_I2C_MEM bytes 42 /* we assume that op points to a memory of at least SAA7146_I2C_MEM bytes
43 size. if we exceed this limit... */ 43 size. if we exceed this limit... */
44 if ( (4*mem) > SAA7146_I2C_MEM ) { 44 if ( (4*mem) > SAA7146_I2C_MEM ) {
45 //fm DEB_I2C(("cannot prepare i2c-message.\n")); 45 //fm DEB_I2C(("cannot prepare i2c-message.\n"));
46 return -ENOMEM; 46 return -ENOMEM;
47 } 47 }
48 48
49 /* be careful: clear out the i2c-mem first */ 49 /* be careful: clear out the i2c-mem first */
50 memset(op,0,sizeof(u32)*mem); 50 memset(op,0,sizeof(u32)*mem);
51 51
52 /* loop through all messages */ 52 /* loop through all messages */
53 for(i = 0; i < num; i++) { 53 for(i = 0; i < num; i++) {
54 54
55 /* insert the address of the i2c-slave. 55 /* insert the address of the i2c-slave.
56 note: we get 7 bit i2c-addresses, 56 note: we get 7 bit i2c-addresses,
57 so we have to perform a translation */ 57 so we have to perform a translation */
58 addr = (m[i].addr*2) + ( (0 != (m[i].flags & I2C_M_RD)) ? 1 : 0); 58 addr = (m[i].addr*2) + ( (0 != (m[i].flags & I2C_M_RD)) ? 1 : 0);
59 h1 = op_count/3; h2 = op_count%3; 59 h1 = op_count/3; h2 = op_count%3;
60 op[h1] |= ( (u8)addr << ((3-h2)*8)); 60 op[h1] |= ( (u8)addr << ((3-h2)*8));
61 op[h1] |= (SAA7146_I2C_START << ((3-h2)*2)); 61 op[h1] |= (SAA7146_I2C_START << ((3-h2)*2));
62 op_count++; 62 op_count++;
63 63
64 /* loop through all bytes of message i */ 64 /* loop through all bytes of message i */
65 for(j = 0; j < m[i].len; j++) { 65 for(j = 0; j < m[i].len; j++) {
66 /* insert the data bytes */ 66 /* insert the data bytes */
67 h1 = op_count/3; h2 = op_count%3; 67 h1 = op_count/3; h2 = op_count%3;
68 op[h1] |= ( (u32)((u8)m[i].buf[j]) << ((3-h2)*8)); 68 op[h1] |= ( (u32)((u8)m[i].buf[j]) << ((3-h2)*8));
69 op[h1] |= ( SAA7146_I2C_CONT << ((3-h2)*2)); 69 op[h1] |= ( SAA7146_I2C_CONT << ((3-h2)*2));
70 op_count++; 70 op_count++;
71 } 71 }
72 72
73 } 73 }
74 74
75 /* have a look at the last byte inserted: 75 /* have a look at the last byte inserted:
76 if it was: ...CONT change it to ...STOP */ 76 if it was: ...CONT change it to ...STOP */
77 h1 = (op_count-1)/3; h2 = (op_count-1)%3; 77 h1 = (op_count-1)/3; h2 = (op_count-1)%3;
78 if ( SAA7146_I2C_CONT == (0x3 & (op[h1] >> ((3-h2)*2))) ) { 78 if ( SAA7146_I2C_CONT == (0x3 & (op[h1] >> ((3-h2)*2))) ) {
79 op[h1] &= ~(0x2 << ((3-h2)*2)); 79 op[h1] &= ~(0x2 << ((3-h2)*2));
80 op[h1] |= (SAA7146_I2C_STOP << ((3-h2)*2)); 80 op[h1] |= (SAA7146_I2C_STOP << ((3-h2)*2));
81 } 81 }
82 82
83 /* return the number of u32s to send */ 83 /* return the number of u32s to send */
84 return mem; 84 return mem;
85 } 85 }
86 86
87 /* this functions loops through all i2c-messages. normally, it should determine 87 /* this functions loops through all i2c-messages. normally, it should determine
88 which bytes were read through the adapter and write them back to the corresponding 88 which bytes were read through the adapter and write them back to the corresponding
89 i2c-message. but instead, we simply write back all bytes. 89 i2c-message. but instead, we simply write back all bytes.
90 fixme: this could be improved. */ 90 fixme: this could be improved. */
91 static int saa7146_i2c_msg_cleanup(const struct i2c_msg *m, int num, u32 *op) 91 static int saa7146_i2c_msg_cleanup(const struct i2c_msg *m, int num, u32 *op)
92 { 92 {
93 int i, j; 93 int i, j;
94 int op_count = 0; 94 int op_count = 0;
95 95
96 /* loop through all messages */ 96 /* loop through all messages */
97 for(i = 0; i < num; i++) { 97 for(i = 0; i < num; i++) {
98 98
99 op_count++; 99 op_count++;
100 100
101 /* loop throgh all bytes of message i */ 101 /* loop throgh all bytes of message i */
102 for(j = 0; j < m[i].len; j++) { 102 for(j = 0; j < m[i].len; j++) {
103 /* write back all bytes that could have been read */ 103 /* write back all bytes that could have been read */
104 m[i].buf[j] = (op[op_count/3] >> ((3-(op_count%3))*8)); 104 m[i].buf[j] = (op[op_count/3] >> ((3-(op_count%3))*8));
105 op_count++; 105 op_count++;
106 } 106 }
107 } 107 }
108 108
109 return 0; 109 return 0;
110 } 110 }
111 111
112 /* this functions resets the i2c-device and returns 0 if everything was fine, otherwise -1 */ 112 /* this functions resets the i2c-device and returns 0 if everything was fine, otherwise -1 */
113 static int saa7146_i2c_reset(struct saa7146_dev *dev) 113 static int saa7146_i2c_reset(struct saa7146_dev *dev)
114 { 114 {
115 /* get current status */ 115 /* get current status */
116 u32 status = saa7146_i2c_status(dev); 116 u32 status = saa7146_i2c_status(dev);
117 117
118 /* clear registers for sure */ 118 /* clear registers for sure */
119 saa7146_write(dev, I2C_STATUS, dev->i2c_bitrate); 119 saa7146_write(dev, I2C_STATUS, dev->i2c_bitrate);
120 saa7146_write(dev, I2C_TRANSFER, 0); 120 saa7146_write(dev, I2C_TRANSFER, 0);
121 121
122 /* check if any operation is still in progress */ 122 /* check if any operation is still in progress */
123 if ( 0 != ( status & SAA7146_I2C_BUSY) ) { 123 if ( 0 != ( status & SAA7146_I2C_BUSY) ) {
124 124
125 /* yes, kill ongoing operation */ 125 /* yes, kill ongoing operation */
126 DEB_I2C(("busy_state detected.\n")); 126 DEB_I2C(("busy_state detected.\n"));
127 127
128 /* set "ABORT-OPERATION"-bit (bit 7)*/ 128 /* set "ABORT-OPERATION"-bit (bit 7)*/
129 saa7146_write(dev, I2C_STATUS, (dev->i2c_bitrate | MASK_07)); 129 saa7146_write(dev, I2C_STATUS, (dev->i2c_bitrate | MASK_07));
130 saa7146_write(dev, MC2, (MASK_00 | MASK_16)); 130 saa7146_write(dev, MC2, (MASK_00 | MASK_16));
131 msleep(SAA7146_I2C_DELAY); 131 msleep(SAA7146_I2C_DELAY);
132 132
133 /* clear all error-bits pending; this is needed because p.123, note 1 */ 133 /* clear all error-bits pending; this is needed because p.123, note 1 */
134 saa7146_write(dev, I2C_STATUS, dev->i2c_bitrate); 134 saa7146_write(dev, I2C_STATUS, dev->i2c_bitrate);
135 saa7146_write(dev, MC2, (MASK_00 | MASK_16)); 135 saa7146_write(dev, MC2, (MASK_00 | MASK_16));
136 msleep(SAA7146_I2C_DELAY); 136 msleep(SAA7146_I2C_DELAY);
137 } 137 }
138 138
139 /* check if any error is (still) present. (this can be necessary because p.123, note 1) */ 139 /* check if any error is (still) present. (this can be necessary because p.123, note 1) */
140 status = saa7146_i2c_status(dev); 140 status = saa7146_i2c_status(dev);
141 141
142 if ( dev->i2c_bitrate != status ) { 142 if ( dev->i2c_bitrate != status ) {
143 143
144 DEB_I2C(("error_state detected. status:0x%08x\n",status)); 144 DEB_I2C(("error_state detected. status:0x%08x\n",status));
145 145
146 /* Repeat the abort operation. This seems to be necessary 146 /* Repeat the abort operation. This seems to be necessary
147 after serious protocol errors caused by e.g. the SAA7740 */ 147 after serious protocol errors caused by e.g. the SAA7740 */
148 saa7146_write(dev, I2C_STATUS, (dev->i2c_bitrate | MASK_07)); 148 saa7146_write(dev, I2C_STATUS, (dev->i2c_bitrate | MASK_07));
149 saa7146_write(dev, MC2, (MASK_00 | MASK_16)); 149 saa7146_write(dev, MC2, (MASK_00 | MASK_16));
150 msleep(SAA7146_I2C_DELAY); 150 msleep(SAA7146_I2C_DELAY);
151 151
152 /* clear all error-bits pending */ 152 /* clear all error-bits pending */
153 saa7146_write(dev, I2C_STATUS, dev->i2c_bitrate); 153 saa7146_write(dev, I2C_STATUS, dev->i2c_bitrate);
154 saa7146_write(dev, MC2, (MASK_00 | MASK_16)); 154 saa7146_write(dev, MC2, (MASK_00 | MASK_16));
155 msleep(SAA7146_I2C_DELAY); 155 msleep(SAA7146_I2C_DELAY);
156 156
157 /* the data sheet says it might be necessary to clear the status 157 /* the data sheet says it might be necessary to clear the status
158 twice after an abort */ 158 twice after an abort */
159 saa7146_write(dev, I2C_STATUS, dev->i2c_bitrate); 159 saa7146_write(dev, I2C_STATUS, dev->i2c_bitrate);
160 saa7146_write(dev, MC2, (MASK_00 | MASK_16)); 160 saa7146_write(dev, MC2, (MASK_00 | MASK_16));
161 msleep(SAA7146_I2C_DELAY); 161 msleep(SAA7146_I2C_DELAY);
162 } 162 }
163 163
164 /* if any error is still present, a fatal error has occured ... */ 164 /* if any error is still present, a fatal error has occured ... */
165 status = saa7146_i2c_status(dev); 165 status = saa7146_i2c_status(dev);
166 if ( dev->i2c_bitrate != status ) { 166 if ( dev->i2c_bitrate != status ) {
167 DEB_I2C(("fatal error. status:0x%08x\n",status)); 167 DEB_I2C(("fatal error. status:0x%08x\n",status));
168 return -1; 168 return -1;
169 } 169 }
170 170
171 return 0; 171 return 0;
172 } 172 }
173 173
174 /* this functions writes out the data-byte 'dword' to the i2c-device. 174 /* this functions writes out the data-byte 'dword' to the i2c-device.
175 it returns 0 if ok, -1 if the transfer failed, -2 if the transfer 175 it returns 0 if ok, -1 if the transfer failed, -2 if the transfer
176 failed badly (e.g. address error) */ 176 failed badly (e.g. address error) */
177 static int saa7146_i2c_writeout(struct saa7146_dev *dev, u32* dword, int short_delay) 177 static int saa7146_i2c_writeout(struct saa7146_dev *dev, u32* dword, int short_delay)
178 { 178 {
179 u32 status = 0, mc2 = 0; 179 u32 status = 0, mc2 = 0;
180 int trial = 0; 180 int trial = 0;
181 unsigned long timeout; 181 unsigned long timeout;
182 182
183 /* write out i2c-command */ 183 /* write out i2c-command */
184 DEB_I2C(("before: 0x%08x (status: 0x%08x), %d\n",*dword,saa7146_read(dev, I2C_STATUS), dev->i2c_op)); 184 DEB_I2C(("before: 0x%08x (status: 0x%08x), %d\n",*dword,saa7146_read(dev, I2C_STATUS), dev->i2c_op));
185 185
186 if( 0 != (SAA7146_USE_I2C_IRQ & dev->ext->flags)) { 186 if( 0 != (SAA7146_USE_I2C_IRQ & dev->ext->flags)) {
187 187
188 saa7146_write(dev, I2C_STATUS, dev->i2c_bitrate); 188 saa7146_write(dev, I2C_STATUS, dev->i2c_bitrate);
189 saa7146_write(dev, I2C_TRANSFER, *dword); 189 saa7146_write(dev, I2C_TRANSFER, *dword);
190 190
191 dev->i2c_op = 1; 191 dev->i2c_op = 1;
192 SAA7146_ISR_CLEAR(dev, MASK_16|MASK_17); 192 SAA7146_ISR_CLEAR(dev, MASK_16|MASK_17);
193 SAA7146_IER_ENABLE(dev, MASK_16|MASK_17); 193 SAA7146_IER_ENABLE(dev, MASK_16|MASK_17);
194 saa7146_write(dev, MC2, (MASK_00 | MASK_16)); 194 saa7146_write(dev, MC2, (MASK_00 | MASK_16));
195 195
196 timeout = HZ/100 + 1; /* 10ms */ 196 timeout = HZ/100 + 1; /* 10ms */
197 timeout = wait_event_interruptible_timeout(dev->i2c_wq, dev->i2c_op == 0, timeout); 197 timeout = wait_event_interruptible_timeout(dev->i2c_wq, dev->i2c_op == 0, timeout);
198 if (timeout == -ERESTARTSYS || dev->i2c_op) { 198 if (timeout == -ERESTARTSYS || dev->i2c_op) {
199 SAA7146_IER_DISABLE(dev, MASK_16|MASK_17); 199 SAA7146_IER_DISABLE(dev, MASK_16|MASK_17);
200 SAA7146_ISR_CLEAR(dev, MASK_16|MASK_17); 200 SAA7146_ISR_CLEAR(dev, MASK_16|MASK_17);
201 if (timeout == -ERESTARTSYS) 201 if (timeout == -ERESTARTSYS)
202 /* a signal arrived */ 202 /* a signal arrived */
203 return -ERESTARTSYS; 203 return -ERESTARTSYS;
204 204
205 printk(KERN_WARNING "saa7146_i2c_writeout: timed out waiting for end of xfer\n"); 205 printk(KERN_WARNING "%s %s [irq]: timed out waiting for end of xfer\n",
206 dev->name, __FUNCTION__);
206 return -EIO; 207 return -EIO;
207 } 208 }
208 status = saa7146_read(dev, I2C_STATUS); 209 status = saa7146_read(dev, I2C_STATUS);
209 } else { 210 } else {
210 saa7146_write(dev, I2C_STATUS, dev->i2c_bitrate); 211 saa7146_write(dev, I2C_STATUS, dev->i2c_bitrate);
211 saa7146_write(dev, I2C_TRANSFER, *dword); 212 saa7146_write(dev, I2C_TRANSFER, *dword);
212 saa7146_write(dev, MC2, (MASK_00 | MASK_16)); 213 saa7146_write(dev, MC2, (MASK_00 | MASK_16));
213 214
214 /* do not poll for i2c-status before upload is complete */ 215 /* do not poll for i2c-status before upload is complete */
215 timeout = jiffies + HZ/100 + 1; /* 10ms */ 216 timeout = jiffies + HZ/100 + 1; /* 10ms */
216 while(1) { 217 while(1) {
217 mc2 = (saa7146_read(dev, MC2) & 0x1); 218 mc2 = (saa7146_read(dev, MC2) & 0x1);
218 if( 0 != mc2 ) { 219 if( 0 != mc2 ) {
219 break; 220 break;
220 } 221 }
221 if (time_after(jiffies,timeout)) { 222 if (time_after(jiffies,timeout)) {
222 printk(KERN_WARNING "saa7146_i2c_writeout: timed out waiting for MC2\n"); 223 printk(KERN_WARNING "%s %s: timed out waiting for MC2\n",
224 dev->name, __FUNCTION__);
223 return -EIO; 225 return -EIO;
224 } 226 }
225 } 227 }
226 /* wait until we get a transfer done or error */ 228 /* wait until we get a transfer done or error */
227 timeout = jiffies + HZ/100 + 1; /* 10ms */ 229 timeout = jiffies + HZ/100 + 1; /* 10ms */
228 /* first read usually delivers bogus results... */ 230 /* first read usually delivers bogus results... */
229 saa7146_i2c_status(dev); 231 saa7146_i2c_status(dev);
230 while(1) { 232 while(1) {
231 status = saa7146_i2c_status(dev); 233 status = saa7146_i2c_status(dev);
232 if ((status & 0x3) != 1) 234 if ((status & 0x3) != 1)
233 break; 235 break;
234 if (time_after(jiffies,timeout)) { 236 if (time_after(jiffies,timeout)) {
235 /* this is normal when probing the bus 237 /* this is normal when probing the bus
236 * (no answer from nonexisistant device...) 238 * (no answer from nonexisistant device...)
237 */ 239 */
238 DEB_I2C(("saa7146_i2c_writeout: timed out waiting for end of xfer\n")); 240 printk(KERN_WARNING "%s %s [poll]: timed out waiting for end of xfer\n",
241 dev->name, __FUNCTION__);
239 return -EIO; 242 return -EIO;
240 } 243 }
241 if (++trial < 50 && short_delay) 244 if (++trial < 50 && short_delay)
242 udelay(10); 245 udelay(10);
243 else 246 else
244 msleep(1); 247 msleep(1);
245 } 248 }
246 } 249 }
247 250
248 /* give a detailed status report */ 251 /* give a detailed status report */
249 if ( 0 != (status & SAA7146_I2C_ERR)) { 252 if ( 0 != (status & (SAA7146_I2C_SPERR | SAA7146_I2C_APERR |
253 SAA7146_I2C_DTERR | SAA7146_I2C_DRERR |
254 SAA7146_I2C_AL | SAA7146_I2C_ERR |
255 SAA7146_I2C_BUSY)) ) {
250 256
257 if ( 0 == (status & SAA7146_I2C_ERR) ||
258 0 == (status & SAA7146_I2C_BUSY) ) {
259 /* it may take some time until ERR goes high - ignore */
260 DEB_I2C(("unexpected i2c status %04x\n", status));
261 }
251 if( 0 != (status & SAA7146_I2C_SPERR) ) { 262 if( 0 != (status & SAA7146_I2C_SPERR) ) {
252 DEB_I2C(("error due to invalid start/stop condition.\n")); 263 DEB_I2C(("error due to invalid start/stop condition.\n"));
253 } 264 }
254 if( 0 != (status & SAA7146_I2C_DTERR) ) { 265 if( 0 != (status & SAA7146_I2C_DTERR) ) {
255 DEB_I2C(("error in data transmission.\n")); 266 DEB_I2C(("error in data transmission.\n"));
256 } 267 }
257 if( 0 != (status & SAA7146_I2C_DRERR) ) { 268 if( 0 != (status & SAA7146_I2C_DRERR) ) {
258 DEB_I2C(("error when receiving data.\n")); 269 DEB_I2C(("error when receiving data.\n"));
259 } 270 }
260 if( 0 != (status & SAA7146_I2C_AL) ) { 271 if( 0 != (status & SAA7146_I2C_AL) ) {
261 DEB_I2C(("error because arbitration lost.\n")); 272 DEB_I2C(("error because arbitration lost.\n"));
262 } 273 }
263 274
264 /* we handle address-errors here */ 275 /* we handle address-errors here */
265 if( 0 != (status & SAA7146_I2C_APERR) ) { 276 if( 0 != (status & SAA7146_I2C_APERR) ) {
266 DEB_I2C(("error in address phase.\n")); 277 DEB_I2C(("error in address phase.\n"));
267 return -EREMOTEIO; 278 return -EREMOTEIO;
268 } 279 }
269 280
270 return -EIO; 281 return -EIO;
271 } 282 }
272 283
273 /* read back data, just in case we were reading ... */ 284 /* read back data, just in case we were reading ... */
274 *dword = saa7146_read(dev, I2C_TRANSFER); 285 *dword = saa7146_read(dev, I2C_TRANSFER);
275 286
276 DEB_I2C(("after: 0x%08x\n",*dword)); 287 DEB_I2C(("after: 0x%08x\n",*dword));
277 return 0; 288 return 0;
278 } 289 }
279 290
280 static int saa7146_i2c_transfer(struct saa7146_dev *dev, const struct i2c_msg *msgs, int num, int retries) 291 static int saa7146_i2c_transfer(struct saa7146_dev *dev, const struct i2c_msg *msgs, int num, int retries)
281 { 292 {
282 int i = 0, count = 0; 293 int i = 0, count = 0;
283 u32* buffer = dev->d_i2c.cpu_addr; 294 u32* buffer = dev->d_i2c.cpu_addr;
284 int err = 0; 295 int err = 0;
285 int address_err = 0; 296 int address_err = 0;
286 int short_delay = 0; 297 int short_delay = 0;
287 298
288 if (mutex_lock_interruptible(&dev->i2c_lock)) 299 if (mutex_lock_interruptible(&dev->i2c_lock))
289 return -ERESTARTSYS; 300 return -ERESTARTSYS;
290 301
291 for(i=0;i<num;i++) { 302 for(i=0;i<num;i++) {
292 DEB_I2C(("msg:%d/%d\n",i+1,num)); 303 DEB_I2C(("msg:%d/%d\n",i+1,num));
293 } 304 }
294 305
295 /* prepare the message(s), get number of u32s to transfer */ 306 /* prepare the message(s), get number of u32s to transfer */
296 count = saa7146_i2c_msg_prepare(msgs, num, buffer); 307 count = saa7146_i2c_msg_prepare(msgs, num, buffer);
297 if ( 0 > count ) { 308 if ( 0 > count ) {
298 err = -1; 309 err = -1;
299 goto out; 310 goto out;
300 } 311 }
301 312
302 if ( count > 3 || 0 != (SAA7146_I2C_SHORT_DELAY & dev->ext->flags) ) 313 if ( count > 3 || 0 != (SAA7146_I2C_SHORT_DELAY & dev->ext->flags) )
303 short_delay = 1; 314 short_delay = 1;
304 315
305 do { 316 do {
306 /* reset the i2c-device if necessary */ 317 /* reset the i2c-device if necessary */
307 err = saa7146_i2c_reset(dev); 318 err = saa7146_i2c_reset(dev);
308 if ( 0 > err ) { 319 if ( 0 > err ) {
309 DEB_I2C(("could not reset i2c-device.\n")); 320 DEB_I2C(("could not reset i2c-device.\n"));
310 goto out; 321 goto out;
311 } 322 }
312 323
313 /* write out the u32s one after another */ 324 /* write out the u32s one after another */
314 for(i = 0; i < count; i++) { 325 for(i = 0; i < count; i++) {
315 err = saa7146_i2c_writeout(dev, &buffer[i], short_delay); 326 err = saa7146_i2c_writeout(dev, &buffer[i], short_delay);
316 if ( 0 != err) { 327 if ( 0 != err) {
317 /* this one is unsatisfying: some i2c slaves on some 328 /* this one is unsatisfying: some i2c slaves on some
318 dvb cards don't acknowledge correctly, so the saa7146 329 dvb cards don't acknowledge correctly, so the saa7146
319 thinks that an address error occured. in that case, the 330 thinks that an address error occured. in that case, the
320 transaction should be retrying, even if an address error 331 transaction should be retrying, even if an address error
321 occured. analog saa7146 based cards extensively rely on 332 occured. analog saa7146 based cards extensively rely on
322 i2c address probing, however, and address errors indicate that a 333 i2c address probing, however, and address errors indicate that a
323 device is really *not* there. retrying in that case 334 device is really *not* there. retrying in that case
324 increases the time the device needs to probe greatly, so 335 increases the time the device needs to probe greatly, so
325 it should be avoided. because of the fact, that only 336 it should be avoided. because of the fact, that only
326 analog based cards use irq based i2c transactions (for dvb 337 analog based cards use irq based i2c transactions (for dvb
327 cards, this screwes up other interrupt sources), we bail out 338 cards, this screwes up other interrupt sources), we bail out
328 completely for analog cards after an address error and trust 339 completely for analog cards after an address error and trust
329 the saa7146 address error detection. */ 340 the saa7146 address error detection. */
330 if ( -EREMOTEIO == err ) { 341 if ( -EREMOTEIO == err ) {
331 if( 0 != (SAA7146_USE_I2C_IRQ & dev->ext->flags)) { 342 if( 0 != (SAA7146_USE_I2C_IRQ & dev->ext->flags)) {
332 goto out; 343 goto out;
333 } 344 }
334 address_err++; 345 address_err++;
335 } 346 }
336 DEB_I2C(("error while sending message(s). starting again.\n")); 347 DEB_I2C(("error while sending message(s). starting again.\n"));
337 break; 348 break;
338 } 349 }
339 } 350 }
340 if( 0 == err ) { 351 if( 0 == err ) {
341 err = num; 352 err = num;
342 break; 353 break;
343 } 354 }
344 355
345 /* delay a bit before retrying */ 356 /* delay a bit before retrying */
346 msleep(10); 357 msleep(10);
347 358
348 } while (err != num && retries--); 359 } while (err != num && retries--);
349 360
350 /* if every retry had an address error, exit right away */ 361 /* if every retry had an address error, exit right away */
351 if (address_err == retries) { 362 if (address_err == retries) {
352 goto out; 363 goto out;
353 } 364 }
354 365
355 /* if any things had to be read, get the results */ 366 /* if any things had to be read, get the results */
356 if ( 0 != saa7146_i2c_msg_cleanup(msgs, num, buffer)) { 367 if ( 0 != saa7146_i2c_msg_cleanup(msgs, num, buffer)) {
357 DEB_I2C(("could not cleanup i2c-message.\n")); 368 DEB_I2C(("could not cleanup i2c-message.\n"));
358 err = -1; 369 err = -1;
359 goto out; 370 goto out;
360 } 371 }
361 372
362 /* return the number of delivered messages */ 373 /* return the number of delivered messages */
363 DEB_I2C(("transmission successful. (msg:%d).\n",err)); 374 DEB_I2C(("transmission successful. (msg:%d).\n",err));
364 out: 375 out:
365 /* another bug in revision 0: the i2c-registers get uploaded randomly by other 376 /* another bug in revision 0: the i2c-registers get uploaded randomly by other
366 uploads, so we better clear them out before continueing */ 377 uploads, so we better clear them out before continueing */
367 if( 0 == dev->revision ) { 378 if( 0 == dev->revision ) {
368 u32 zero = 0; 379 u32 zero = 0;
369 saa7146_i2c_reset(dev); 380 saa7146_i2c_reset(dev);
370 if( 0 != saa7146_i2c_writeout(dev, &zero, short_delay)) { 381 if( 0 != saa7146_i2c_writeout(dev, &zero, short_delay)) {
371 INFO(("revision 0 error. this should never happen.\n")); 382 INFO(("revision 0 error. this should never happen.\n"));
372 } 383 }
373 } 384 }
374 385
375 mutex_unlock(&dev->i2c_lock); 386 mutex_unlock(&dev->i2c_lock);
376 return err; 387 return err;
377 } 388 }
378 389
379 /* utility functions */ 390 /* utility functions */
380 static int saa7146_i2c_xfer(struct i2c_adapter* adapter, struct i2c_msg *msg, int num) 391 static int saa7146_i2c_xfer(struct i2c_adapter* adapter, struct i2c_msg *msg, int num)
381 { 392 {
382 struct saa7146_dev* dev = i2c_get_adapdata(adapter); 393 struct saa7146_dev* dev = i2c_get_adapdata(adapter);
383 394
384 /* use helper function to transfer data */ 395 /* use helper function to transfer data */
385 return saa7146_i2c_transfer(dev, msg, num, adapter->retries); 396 return saa7146_i2c_transfer(dev, msg, num, adapter->retries);
386 } 397 }
387 398
388 399
389 /*****************************************************************************/ 400 /*****************************************************************************/
390 /* i2c-adapter helper functions */ 401 /* i2c-adapter helper functions */
391 #include <linux/i2c-id.h> 402 #include <linux/i2c-id.h>
392 403
393 /* exported algorithm data */ 404 /* exported algorithm data */
394 static struct i2c_algorithm saa7146_algo = { 405 static struct i2c_algorithm saa7146_algo = {
395 .master_xfer = saa7146_i2c_xfer, 406 .master_xfer = saa7146_i2c_xfer,
396 .functionality = saa7146_i2c_func, 407 .functionality = saa7146_i2c_func,
397 }; 408 };
398 409
399 int saa7146_i2c_adapter_prepare(struct saa7146_dev *dev, struct i2c_adapter *i2c_adapter, u32 bitrate) 410 int saa7146_i2c_adapter_prepare(struct saa7146_dev *dev, struct i2c_adapter *i2c_adapter, u32 bitrate)
400 { 411 {
401 DEB_EE(("bitrate: 0x%08x\n",bitrate)); 412 DEB_EE(("bitrate: 0x%08x\n",bitrate));
402 413
403 /* enable i2c-port pins */ 414 /* enable i2c-port pins */
404 saa7146_write(dev, MC1, (MASK_08 | MASK_24)); 415 saa7146_write(dev, MC1, (MASK_08 | MASK_24));
405 416
406 dev->i2c_bitrate = bitrate; 417 dev->i2c_bitrate = bitrate;
407 saa7146_i2c_reset(dev); 418 saa7146_i2c_reset(dev);
408 419
409 if( NULL != i2c_adapter ) { 420 if( NULL != i2c_adapter ) {
410 BUG_ON(!i2c_adapter->class); 421 BUG_ON(!i2c_adapter->class);
411 i2c_set_adapdata(i2c_adapter,dev); 422 i2c_set_adapdata(i2c_adapter,dev);
412 i2c_adapter->dev.parent = &dev->pci->dev; 423 i2c_adapter->dev.parent = &dev->pci->dev;
413 i2c_adapter->algo = &saa7146_algo; 424 i2c_adapter->algo = &saa7146_algo;
414 i2c_adapter->algo_data = NULL; 425 i2c_adapter->algo_data = NULL;
415 i2c_adapter->id = I2C_HW_SAA7146; 426 i2c_adapter->id = I2C_HW_SAA7146;
416 i2c_adapter->timeout = SAA7146_I2C_TIMEOUT; 427 i2c_adapter->timeout = SAA7146_I2C_TIMEOUT;
417 i2c_adapter->retries = SAA7146_I2C_RETRIES; 428 i2c_adapter->retries = SAA7146_I2C_RETRIES;
418 } 429 }
419 430
420 return 0; 431 return 0;
421 } 432 }
422 433