aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/irda
diff options
context:
space:
mode:
authorBen Hutchings <ben@decadent.org.uk>2011-03-28 13:10:43 -0400
committerDavid S. Miller <davem@davemloft.net>2011-03-30 03:12:32 -0400
commitabc45592bce8267a8e651c12ce94a1f83eaac7a6 (patch)
tree26734a7c7c65a0ee856f31a5e9634778b6041f48 /drivers/net/irda
parent93ca3bb5df9bc8b2c60485e1cc6507c3d7c8e1fa (diff)
via-ircc: Use pci_{get, set}_drvdata() instead of static pointer variable
via-ircc still maintains its own array of device pointers in Linux 2.4 style. Worse, it always uses index 0, so it will crash if there are multiple suitable devices in the system. Signed-off-by: Ben Hutchings <ben@decadent.org.uk> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/irda')
-rw-r--r--drivers/net/irda/via-ircc.c82
1 files changed, 15 insertions, 67 deletions
diff --git a/drivers/net/irda/via-ircc.c b/drivers/net/irda/via-ircc.c
index 67c0ad42d818..cc6faca35160 100644
--- a/drivers/net/irda/via-ircc.c
+++ b/drivers/net/irda/via-ircc.c
@@ -75,15 +75,9 @@ static int dongle_id = 0; /* default: probe */
75/* We can't guess the type of connected dongle, user *must* supply it. */ 75/* We can't guess the type of connected dongle, user *must* supply it. */
76module_param(dongle_id, int, 0); 76module_param(dongle_id, int, 0);
77 77
78/* FIXME : we should not need this, because instances should be automatically
79 * managed by the PCI layer. Especially that we seem to only be using the
80 * first entry. Jean II */
81/* Max 4 instances for now */
82static struct via_ircc_cb *dev_self[] = { NULL, NULL, NULL, NULL };
83
84/* Some prototypes */ 78/* Some prototypes */
85static int via_ircc_open(int i, chipio_t * info, unsigned int id); 79static int via_ircc_open(struct pci_dev *pdev, chipio_t * info,
86static int via_ircc_close(struct via_ircc_cb *self); 80 unsigned int id);
87static int via_ircc_dma_receive(struct via_ircc_cb *self); 81static int via_ircc_dma_receive(struct via_ircc_cb *self);
88static int via_ircc_dma_receive_complete(struct via_ircc_cb *self, 82static int via_ircc_dma_receive_complete(struct via_ircc_cb *self,
89 int iobase); 83 int iobase);
@@ -215,7 +209,7 @@ static int __devinit via_init_one (struct pci_dev *pcidev, const struct pci_devi
215 pci_write_config_byte(pcidev,0x42,(bTmp | 0xf0)); 209 pci_write_config_byte(pcidev,0x42,(bTmp | 0xf0));
216 pci_write_config_byte(pcidev,0x5a,0xc0); 210 pci_write_config_byte(pcidev,0x5a,0xc0);
217 WriteLPCReg(0x28, 0x70 ); 211 WriteLPCReg(0x28, 0x70 );
218 if (via_ircc_open(0, &info,0x3076) == 0) 212 if (via_ircc_open(pcidev, &info, 0x3076) == 0)
219 rc=0; 213 rc=0;
220 } else 214 } else
221 rc = -ENODEV; //IR not turn on 215 rc = -ENODEV; //IR not turn on
@@ -254,7 +248,7 @@ static int __devinit via_init_one (struct pci_dev *pcidev, const struct pci_devi
254 info.irq=FirIRQ; 248 info.irq=FirIRQ;
255 info.dma=FirDRQ1; 249 info.dma=FirDRQ1;
256 info.dma2=FirDRQ0; 250 info.dma2=FirDRQ0;
257 if (via_ircc_open(0, &info,0x3096) == 0) 251 if (via_ircc_open(pcidev, &info, 0x3096) == 0)
258 rc=0; 252 rc=0;
259 } else 253 } else
260 rc = -ENODEV; //IR not turn on !!!!! 254 rc = -ENODEV; //IR not turn on !!!!!
@@ -264,48 +258,10 @@ static int __devinit via_init_one (struct pci_dev *pcidev, const struct pci_devi
264 return rc; 258 return rc;
265} 259}
266 260
267/*
268 * Function via_ircc_clean ()
269 *
270 * Close all configured chips
271 *
272 */
273static void via_ircc_clean(void)
274{
275 int i;
276
277 IRDA_DEBUG(3, "%s()\n", __func__);
278
279 for (i=0; i < ARRAY_SIZE(dev_self); i++) {
280 if (dev_self[i])
281 via_ircc_close(dev_self[i]);
282 }
283}
284
285static void __devexit via_remove_one (struct pci_dev *pdev)
286{
287 IRDA_DEBUG(3, "%s()\n", __func__);
288
289 /* FIXME : This is ugly. We should use pci_get_drvdata(pdev);
290 * to get our driver instance and call directly via_ircc_close().
291 * See vlsi_ir for details...
292 * Jean II */
293 via_ircc_clean();
294
295 /* FIXME : This should be in via_ircc_close(), because here we may
296 * theoritically disable still configured devices :-( - Jean II */
297 pci_disable_device(pdev);
298}
299
300static void __exit via_ircc_cleanup(void) 261static void __exit via_ircc_cleanup(void)
301{ 262{
302 IRDA_DEBUG(3, "%s()\n", __func__); 263 IRDA_DEBUG(3, "%s()\n", __func__);
303 264
304 /* FIXME : This should be redundant, as pci_unregister_driver()
305 * should call via_remove_one() on each device.
306 * Jean II */
307 via_ircc_clean();
308
309 /* Cleanup all instances of the driver */ 265 /* Cleanup all instances of the driver */
310 pci_unregister_driver (&via_driver); 266 pci_unregister_driver (&via_driver);
311} 267}
@@ -324,12 +280,13 @@ static const struct net_device_ops via_ircc_fir_ops = {
324}; 280};
325 281
326/* 282/*
327 * Function via_ircc_open (iobase, irq) 283 * Function via_ircc_open(pdev, iobase, irq)
328 * 284 *
329 * Open driver instance 285 * Open driver instance
330 * 286 *
331 */ 287 */
332static __devinit int via_ircc_open(int i, chipio_t * info, unsigned int id) 288static __devinit int via_ircc_open(struct pci_dev *pdev, chipio_t * info,
289 unsigned int id)
333{ 290{
334 struct net_device *dev; 291 struct net_device *dev;
335 struct via_ircc_cb *self; 292 struct via_ircc_cb *self;
@@ -337,9 +294,6 @@ static __devinit int via_ircc_open(int i, chipio_t * info, unsigned int id)
337 294
338 IRDA_DEBUG(3, "%s()\n", __func__); 295 IRDA_DEBUG(3, "%s()\n", __func__);
339 296
340 if (i >= ARRAY_SIZE(dev_self))
341 return -ENOMEM;
342
343 /* Allocate new instance of the driver */ 297 /* Allocate new instance of the driver */
344 dev = alloc_irdadev(sizeof(struct via_ircc_cb)); 298 dev = alloc_irdadev(sizeof(struct via_ircc_cb));
345 if (dev == NULL) 299 if (dev == NULL)
@@ -349,13 +303,8 @@ static __devinit int via_ircc_open(int i, chipio_t * info, unsigned int id)
349 self->netdev = dev; 303 self->netdev = dev;
350 spin_lock_init(&self->lock); 304 spin_lock_init(&self->lock);
351 305
352 /* FIXME : We should store our driver instance in the PCI layer, 306 pci_set_drvdata(pdev, self);
353 * using pci_set_drvdata(), not in this array. 307
354 * See vlsi_ir for details... - Jean II */
355 /* FIXME : 'i' is always 0 (see via_init_one()) :-( - Jean II */
356 /* Need to store self somewhere */
357 dev_self[i] = self;
358 self->index = i;
359 /* Initialize Resource */ 308 /* Initialize Resource */
360 self->io.cfg_base = info->cfg_base; 309 self->io.cfg_base = info->cfg_base;
361 self->io.fir_base = info->fir_base; 310 self->io.fir_base = info->fir_base;
@@ -463,25 +412,24 @@ static __devinit int via_ircc_open(int i, chipio_t * info, unsigned int id)
463 err_out2: 412 err_out2:
464 release_region(self->io.fir_base, self->io.fir_ext); 413 release_region(self->io.fir_base, self->io.fir_ext);
465 err_out1: 414 err_out1:
415 pci_set_drvdata(pdev, NULL);
466 free_netdev(dev); 416 free_netdev(dev);
467 dev_self[i] = NULL;
468 return err; 417 return err;
469} 418}
470 419
471/* 420/*
472 * Function via_ircc_close (self) 421 * Function via_remove_one(pdev)
473 * 422 *
474 * Close driver instance 423 * Close driver instance
475 * 424 *
476 */ 425 */
477static int via_ircc_close(struct via_ircc_cb *self) 426static void __devexit via_remove_one(struct pci_dev *pdev)
478{ 427{
428 struct via_ircc_cb *self = pci_get_drvdata(pdev);
479 int iobase; 429 int iobase;
480 430
481 IRDA_DEBUG(3, "%s()\n", __func__); 431 IRDA_DEBUG(3, "%s()\n", __func__);
482 432
483 IRDA_ASSERT(self != NULL, return -1;);
484
485 iobase = self->io.fir_base; 433 iobase = self->io.fir_base;
486 434
487 ResetChip(iobase, 5); //hardware reset. 435 ResetChip(iobase, 5); //hardware reset.
@@ -498,11 +446,11 @@ static int via_ircc_close(struct via_ircc_cb *self)
498 if (self->rx_buff.head) 446 if (self->rx_buff.head)
499 dma_free_coherent(NULL, self->rx_buff.truesize, 447 dma_free_coherent(NULL, self->rx_buff.truesize,
500 self->rx_buff.head, self->rx_buff_dma); 448 self->rx_buff.head, self->rx_buff_dma);
501 dev_self[self->index] = NULL; 449 pci_set_drvdata(pdev, NULL);
502 450
503 free_netdev(self->netdev); 451 free_netdev(self->netdev);
504 452
505 return 0; 453 pci_disable_device(pdev);
506} 454}
507 455
508/* 456/*