~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/net/irda/via-ircc.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
2004-02-16: <sda@bdit.de>
31
31
- Removed unneeded 'legacy' pci stuff.
32
 
- Make sure SIR mode is set (hw_init()) before calling mode-dependant stuff.
 
32
- Make sure SIR mode is set (hw_init()) before calling mode-dependent stuff.
33
33
- On speed change from core, don't send SIR frame with new speed. 
34
34
  Use current speed and change speeds later.
35
35
- Make module-param dongle_id actually work.
75
75
/* We can't guess the type of connected dongle, user *must* supply it. */
76
76
module_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 */
82
 
static struct via_ircc_cb *dev_self[] = { NULL, NULL, NULL, NULL };
83
 
 
84
78
/* Some prototypes */
85
 
static int via_ircc_open(int i, chipio_t * info, unsigned int id);
86
 
static int via_ircc_close(struct via_ircc_cb *self);
 
79
static int via_ircc_open(struct pci_dev *pdev, chipio_t * info,
 
80
                         unsigned int id);
87
81
static int via_ircc_dma_receive(struct via_ircc_cb *self);
88
82
static int via_ircc_dma_receive_complete(struct via_ircc_cb *self,
89
83
                                         int iobase);
215
209
                        pci_write_config_byte(pcidev,0x42,(bTmp | 0xf0));
216
210
                        pci_write_config_byte(pcidev,0x5a,0xc0);
217
211
                        WriteLPCReg(0x28, 0x70 );
218
 
                        if (via_ircc_open(0, &info,0x3076) == 0)
 
212
                        if (via_ircc_open(pcidev, &info, 0x3076) == 0)
219
213
                                rc=0;
220
214
                } else
221
215
                        rc = -ENODEV; //IR not turn on   
254
248
                        info.irq=FirIRQ;
255
249
                        info.dma=FirDRQ1;
256
250
                        info.dma2=FirDRQ0;
257
 
                        if (via_ircc_open(0, &info,0x3096) == 0)
 
251
                        if (via_ircc_open(pcidev, &info, 0x3096) == 0)
258
252
                                rc=0;
259
253
                } else
260
254
                        rc = -ENODEV; //IR not turn on !!!!!
264
258
        return rc;
265
259
}
266
260
 
267
 
/*
268
 
 * Function via_ircc_clean ()
269
 
 *
270
 
 *    Close all configured chips
271
 
 *
272
 
 */
273
 
static 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
 
 
285
 
static 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
 
 
300
261
static void __exit via_ircc_cleanup(void)
301
262
{
302
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
265
        /* Cleanup all instances of the driver */
310
266
        pci_unregister_driver (&via_driver); 
311
267
}
324
280
};
325
281
 
326
282
/*
327
 
 * Function via_ircc_open (iobase, irq)
 
283
 * Function via_ircc_open(pdev, iobase, irq)
328
284
 *
329
285
 *    Open driver instance
330
286
 *
331
287
 */
332
 
static __devinit int via_ircc_open(int i, chipio_t * info, unsigned int id)
 
288
static __devinit int via_ircc_open(struct pci_dev *pdev, chipio_t * info,
 
289
                                   unsigned int id)
333
290
{
334
291
        struct net_device *dev;
335
292
        struct via_ircc_cb *self;
337
294
 
338
295
        IRDA_DEBUG(3, "%s()\n", __func__);
339
296
 
340
 
        if (i >= ARRAY_SIZE(dev_self))
341
 
                return -ENOMEM;
342
 
 
343
297
        /* Allocate new instance of the driver */
344
298
        dev = alloc_irdadev(sizeof(struct via_ircc_cb));
345
299
        if (dev == NULL) 
349
303
        self->netdev = dev;
350
304
        spin_lock_init(&self->lock);
351
305
 
352
 
        /* FIXME : We should store our driver instance in the PCI layer,
353
 
         * using pci_set_drvdata(), not in this array.
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;
 
306
        pci_set_drvdata(pdev, self);
 
307
 
359
308
        /* Initialize Resource */
360
309
        self->io.cfg_base = info->cfg_base;
361
310
        self->io.fir_base = info->fir_base;
385
334
        self->io.dongle_id = dongle_id;
386
335
 
387
336
        /* The only value we must override it the baudrate */
388
 
        /* Maximum speeds and capabilities are dongle-dependant. */
 
337
        /* Maximum speeds and capabilities are dongle-dependent. */
389
338
        switch( self->io.dongle_id ){
390
339
        case 0x0d:
391
340
                self->qos.baud_rate.bits =
414
363
 
415
364
        /* Allocate memory if needed */
416
365
        self->rx_buff.head =
417
 
                dma_alloc_coherent(NULL, self->rx_buff.truesize,
 
366
                dma_alloc_coherent(&pdev->dev, self->rx_buff.truesize,
418
367
                                   &self->rx_buff_dma, GFP_KERNEL);
419
368
        if (self->rx_buff.head == NULL) {
420
369
                err = -ENOMEM;
423
372
        memset(self->rx_buff.head, 0, self->rx_buff.truesize);
424
373
 
425
374
        self->tx_buff.head =
426
 
                dma_alloc_coherent(NULL, self->tx_buff.truesize,
 
375
                dma_alloc_coherent(&pdev->dev, self->tx_buff.truesize,
427
376
                                   &self->tx_buff_dma, GFP_KERNEL);
428
377
        if (self->tx_buff.head == NULL) {
429
378
                err = -ENOMEM;
455
404
        via_hw_init(self);
456
405
        return 0;
457
406
 err_out4:
458
 
        dma_free_coherent(NULL, self->tx_buff.truesize,
 
407
        dma_free_coherent(&pdev->dev, self->tx_buff.truesize,
459
408
                          self->tx_buff.head, self->tx_buff_dma);
460
409
 err_out3:
461
 
        dma_free_coherent(NULL, self->rx_buff.truesize,
 
410
        dma_free_coherent(&pdev->dev, self->rx_buff.truesize,
462
411
                          self->rx_buff.head, self->rx_buff_dma);
463
412
 err_out2:
464
413
        release_region(self->io.fir_base, self->io.fir_ext);
465
414
 err_out1:
 
415
        pci_set_drvdata(pdev, NULL);
466
416
        free_netdev(dev);
467
 
        dev_self[i] = NULL;
468
417
        return err;
469
418
}
470
419
 
471
420
/*
472
 
 * Function via_ircc_close (self)
 
421
 * Function via_remove_one(pdev)
473
422
 *
474
423
 *    Close driver instance
475
424
 *
476
425
 */
477
 
static int via_ircc_close(struct via_ircc_cb *self)
 
426
static void __devexit via_remove_one(struct pci_dev *pdev)
478
427
{
 
428
        struct via_ircc_cb *self = pci_get_drvdata(pdev);
479
429
        int iobase;
480
430
 
481
431
        IRDA_DEBUG(3, "%s()\n", __func__);
482
432
 
483
 
        IRDA_ASSERT(self != NULL, return -1;);
484
 
 
485
433
        iobase = self->io.fir_base;
486
434
 
487
435
        ResetChip(iobase, 5);   //hardware reset.
493
441
                   __func__, self->io.fir_base);
494
442
        release_region(self->io.fir_base, self->io.fir_ext);
495
443
        if (self->tx_buff.head)
496
 
                dma_free_coherent(NULL, self->tx_buff.truesize,
 
444
                dma_free_coherent(&pdev->dev, self->tx_buff.truesize,
497
445
                                  self->tx_buff.head, self->tx_buff_dma);
498
446
        if (self->rx_buff.head)
499
 
                dma_free_coherent(NULL, self->rx_buff.truesize,
 
447
                dma_free_coherent(&pdev->dev, self->rx_buff.truesize,
500
448
                                  self->rx_buff.head, self->rx_buff_dma);
501
 
        dev_self[self->index] = NULL;
 
449
        pci_set_drvdata(pdev, NULL);
502
450
 
503
451
        free_netdev(self->netdev);
504
452
 
505
 
        return 0;
 
453
        pci_disable_device(pdev);
506
454
}
507
455
 
508
456
/*