Annotation of margi2/margi.c, revision 1.6

1.1       cvs         1: /* 
                      2:     margi.c
                      3: 
                      4:     Copyright (C) Marcus Metzler for convergence integrated media.
                      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 "margi.h"
                     22: 
                     23: #include <pcmcia/version.h>
                     24: #include <pcmcia/cs_types.h>
                     25: #include <pcmcia/cs.h>
                     26: #include <pcmcia/cistpl.h>
                     27: #include <pcmcia/cisreg.h>
                     28: #include <pcmcia/bus_ops.h>
                     29: #include <pcmcia/ds.h>
                     30: 
                     31: 
                     32: 
                     33: #include "l64014.h"
                     34: #include "l64021.h"
                     35: #include "i2c.h"
                     36: #include "decoder.h"
                     37: #include "dram.h"
                     38: #include "video.h"
                     39: #include "cvdv.h"
                     40: 
                     41: //#define USE_BH 1
                     42: #ifdef USE_BH
                     43: #define MARGI_BH 31
                     44: // shouldn't be a number, but then MARGI_BH must be entered into interrupt.h
                     45: #endif
                     46: 
                     47: MODULE_AUTHOR(AUTHOR);
                     48: MODULE_DESCRIPTION(MEDDEVNAME " Driver V." DVERSION);
                     49: 
                     50: #ifdef PCMCIA_DEBUG
                     51: static int pc_debug = PCMCIA_DEBUG;
                     52: MODULE_PARM(pc_debug, "i");
                     53: #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
                     54: static char *version = "margi_cs.c 0.42 11/1/2000 (Marcus Metzler)";
                     55: #else
                     56: #define DEBUG(n, args...)
                     57: #endif
                     58: 
                     59: #define MAX_DEV 4
                     60: #define DEVICE_NR(minor)       ((minor)>>4)
                     61: 
                     62: /*====================================================================*/
                     63: 
                     64: /* Parameters that can be set with 'insmod' */
                     65: 
                     66: /* Release IO ports after configuration? */
                     67: static int free_ports = 0;
                     68: 
                     69: /* The old way: bit map of interrupts to choose from */
                     70: /* This means pick from 15, 14, 12, 11, 10, 9, 7, 5, 4, and 3 */
                     71: static u_int irq_mask = 0xdeb8;
                     72: /* Newer, simpler way of listing specific interrupts */
                     73: static int irq_list[4] = { -1 };
                     74: 
                     75: MODULE_PARM(free_ports, "i");
                     76: MODULE_PARM(irq_mask, "i");
                     77: MODULE_PARM(irq_list, "1-4i");
                     78: 
                     79: extern unsigned int major_device_number;
                     80: extern struct file_operations cvdv_fileops;
                     81: 
                     82: 
                     83: typedef struct margi_info_t {
                     84:        dev_link_t link;
                     85:        dev_node_t node;
                     86:        struct cvdv_cards card;
                     87:        int stop;
                     88: } margi_info_t;
                     89: 
                     90: 
                     91: 
                     92: /*
                     93:    The event() function is this driver's Card Services event handler.
                     94:    It will be called by Card Services when an appropriate card status
                     95:    event is received.  The config() and release() entry points are
                     96:    used to configure or release a socket, in response to card
                     97:    insertion and ejection events.  They are invoked from the margi
                     98:    event handler. 
                     99: */
                    100: 
                    101: static void margi_config(dev_link_t * link);
                    102: static void margi_release(u_long arg);
                    103: static int margi_event(event_t event, int priority,
                    104:                       event_callback_args_t * args);
                    105: /*
                    106:    The attach() and detach() entry points are used to create and destroy
                    107:    "instances" of the driver, where each instance represents everything
                    108:    needed to manage one actual PCMCIA card.
                    109: */
                    110: 
                    111: static dev_link_t *margi_attach(void);
                    112: static void margi_detach(dev_link_t *);
                    113: static u_char read_lsi_status(struct cvdv_cards *card);
                    114: 
                    115: /*
                    116:    You'll also need to prototype all the functions that will actually
                    117:    be used to talk to your device.  See 'memory_cs' for a good example
                    118:    of a fully self-sufficient driver; the other drivers rely more or
                    119:    less on other parts of the kernel.
                    120: */
                    121: 
                    122: /*
                    123:    The dev_info variable is the "key" that is used to match up this
                    124:    device driver with appropriate cards, through the card configuration
                    125:    database.
                    126: */
                    127: 
                    128: static dev_link_t *dev_table[MAX_DEV] = { NULL, /* ... */  };
                    129: 
                    130: static dev_info_t dev_info = "margi_cs";
                    131: 
                    132: /*
                    133:    A linked list of "instances" of the margi device.  Each actual
                    134:    PCMCIA card corresponds to one device instance, and is described
                    135:    by one dev_link_t structure (defined in ds.h).
                    136: 
                    137:    You may not want to use a linked list for this -- for example, the
                    138:    memory card driver uses an array of dev_link_t pointers, where minor
                    139:    device numbers are used to derive the corresponding array index.
                    140: */
                    141: 
                    142: static dev_link_t *dev_list = NULL;
                    143: 
                    144: /*
                    145:    A dev_link_t structure has fields for most things that are needed
                    146:    to keep track of a socket, but there will usually be some device
                    147:    specific information that also needs to be kept track of.  The
                    148:    'priv' pointer in a dev_link_t structure can be used to point to
                    149:    a device-specific private data structure, like this.
                    150: 
                    151:    To simplify the data structure handling, we actually include the
                    152:    dev_link_t structure in the device's private data structure.
                    153: 
                    154:    A driver needs to provide a dev_node_t structure for each device
                    155:    on a card.  In some cases, there is only one device per card (for
                    156:    example, ethernet cards, modems).  In other cases, there may be
                    157:    many actual or logical devices (SCSI adapters, memory cards with
                    158:    multiple partitions).  The dev_node_t structures need to be kept
                    159:    in a linked list starting at the 'dev' field of a dev_link_t
                    160:    structure.  We allocate them in the card's private data structure,
                    161:    because they generally shouldn't be allocated dynamically.
                    162: 
                    163:    In this case, we also provide a flag to indicate if a device is
                    164:    "stopped" due to a power management event, or card ejection.  The
                    165:    device IO routines can use a flag like this to throttle IO to a
                    166:    card that is not ready to accept it.
                    167: 
                    168:    The bus_operations pointer is used on platforms for which we need
                    169:    to use special socket-specific versions of normal IO primitives
                    170:    (inb, outb, readb, writeb, etc) for card IO.
                    171: */
                    172: 
                    173: 
                    174: void DACSetFrequency(struct cvdv_cards *card, int khz, int multiple) {
                    175:        u8 b =  read_indexed_register(card, IIO_OSC_AUD);
                    176: 
                    177:        b &= 0xf8;
                    178: 
                    179:        switch (khz){
1.2       rjkm      180:        case 32:
                    181:                b |= 0x04;
                    182:                break;
1.1       cvs       183:        case 48:
                    184:                b |= 0x00;
                    185:                break;
                    186:        case 44:
                    187:                b |= 0x01;
                    188:                break;
                    189:        case 96:
                    190:                b |= 0x02;
                    191:                break;
                    192:        default:
                    193:                b |= 0x00;
                    194:                break;
                    195:        }
                    196:        write_indexed_register(card, IIO_OSC_AUD, b);
                    197: 
                    198: }
                    199: 
                    200: int MargiFreeBuffers(struct cvdv_cards *card)
                    201: {
                    202:        printk(KERN_DEBUG LOGNAME ": -- MargiFreeBuffers\n");
                    203:        
                    204:        ring_destroy(&(card->rbuf));
                    205:        card->use_ring = 0;
                    206:        return 0;
                    207: }
                    208: 
                    209: 
                    210: int MargiSetBuffers(struct cvdv_cards *card, u32 size)
                    211: {
                    212:        MargiFreeBuffers(card);
                    213:        printk(KERN_DEBUG LOGNAME ": -- MargiSetBuffers(%d)\n",
                    214:               size);
                    215: 
                    216:        ring_init(&(card->rbuf),size);
                    217:        card->use_ring = 1;
                    218:        return 0;
                    219: 
                    220: }
                    221: 
                    222: int MargiFlush (struct cvdv_cards *card)
                    223: {
                    224:        int co = 0;
                    225:        int i;
                    226:        for (i=0;i<100;i++)
                    227:                MargiPush(card, 32, FlushPacket);
                    228:        while (ring_write_rest(&(card->rbuf))  && co<100) co++;
                    229:        VideoSetBackground(card, 1, 0, 0, 0);   // black
                    230: 
                    231:        ring_flush(&(card->rbuf));
                    232:        card->DMAABusy = 0;
                    233: 
                    234: 
                    235:        DecoderStopChannel(card);
                    236:        DecoderStreamReset(card);
                    237:        DecoderSetupReset(card);
                    238:        card->channelrun = 0;
                    239: 
                    240:        printk(KERN_DEBUG LOGNAME ": Margi Flush \n");
                    241:        return 0;
                    242: }
                    243: 
                    244: 
                    245: 
                    246: 
                    247: int MargiPush(struct cvdv_cards *card, int count, const char *data)
                    248: {
                    249: //     printk(KERN_DEBUG LOGNAME ": -- MargiPush(%d,0x%08lX)\n",count,(long)data);
                    250:        if (!card->use_ring)
                    251:                return 0;
                    252: 
                    253:        if (!card->channelrun){
                    254:                DecoderStartChannel(card);
                    255:        }
                    256: 
                    257:        card->DMAABusy = 1;
                    258:        /*
                    259:          while (ring_write_rest(&(card->rbuf)) < count && co < 100){
                    260:        printk("buffer waiting to write\n");
                    261:          co++;
                    262: //       interruptible_sleep_on(&card->wqA);
                    263: //       if (signal_pending(current))
                    264: //         return 0;
                    265:        }
                    266:        */
                    267:        count = ring_write(&(card->rbuf),data,count);
                    268:        return count;
                    269: }
                    270: 
                    271: int DecoderStartChannel(struct cvdv_cards *card)
                    272: {
                    273:        //DecoderSetByte(card,0x007,0x01);  // channel start
                    274:        DecoderMaskByte(card, 0x007, 0xC3, 0xC3);       // channel start
                    275:        //DecoderSetByte(card,0x005,0x01);  // invert channel clock on
                    276:        //DecoderDelByte(card,0x005,0x02);  // channel request mode off
                    277:        //DecoderDelByte(card,0x005,0x04);  // channel pause off
                    278:        //DecoderDelByte(card,0x005,0x08);  // channel bypass enable off
                    279: #ifdef BYPASS 
                    280:        DecoderMaskByte(card,0x005,0x0F,0x08);
                    281: #else
                    282:        DecoderMaskByte(card,0x005,0x0F,0x01);
                    283: #endif
                    284:        card->channelrun = 1;
                    285:        return 0;
                    286: }
                    287: 
                    288: int DecoderStopChannel(struct cvdv_cards *card)
                    289: {
                    290:   //   DecoderDelByte(card,0x007,0x01);  // channel reset
                    291:        DecoderMaskByte(card, 0x007, 0xC3, 0xC2);       // channel reset
                    292:        DecoderSetByte(card, 0x005, 0x04);      // channel pause
                    293:        card->channelrun = 0;
                    294:        return 0;
                    295: }
                    296: 
                    297: u32 DecoderGetAudioBufferSpace(struct cvdv_cards *card)
                    298: {
                    299: 
                    300:        u32 MaxSize, Size;
                    301: 
                    302:        MaxSize = card->AudioESSize;
                    303:        Size = DecoderGetAudioESLevel(card);
                    304: 
                    305:        if (Size>MaxSize)
                    306:          return 0;
                    307:        return (MaxSize - Size);
                    308: 
                    309: }
                    310: 
                    311: u32 DecoderGetVideoBufferSpace(struct cvdv_cards *card)
                    312: {
                    313: 
                    314:        u32 MaxSize, Size;
                    315: 
                    316:        MaxSize = card->VideoESSize;
                    317:        Size = DecoderGetVideoESLevel(card);
                    318: 
                    319:        if (Size>MaxSize)
                    320:          return 0;
                    321:        return (MaxSize - Size);
                    322: 
                    323: }
                    324: 
                    325: u32 DecoderGetBufferSpace(struct cvdv_cards *card)
                    326: {
                    327:        u32 audio,video;
                    328:        
                    329:        audio = DecoderGetAudioBufferSpace(card);
                    330:        video = DecoderGetVideoBufferSpace(card);
                    331: 
1.2       rjkm      332:        if (audio > 2048) audio -= 2048;
                    333:        if (video > 16384) video -= 16384;
1.1       cvs       334: 
                    335:        if (audio < video) return audio;
                    336:        return video;
                    337: }
                    338: 
                    339: static int ringDMA (struct cvdv_cards *card){
                    340:        
                    341:        u32 size = 0;
                    342:        u_char stat;
                    343:        dev_link_t *link = &(((margi_info_t *) card->margi)->link);
                    344:        u32 count=0;
                    345:        u8 data;
                    346:        
                    347:        count = ring_read_rest(&(card->rbuf));
1.4       rjkm      348:        if (count < 2048) {
1.5       mocm      349:                //card->DMAABusy = 0;
1.1       cvs       350:                wake_up_interruptible(&(card->wqA));
                    351:                return 0;
1.4       rjkm      352:        }
1.1       cvs       353:        stat = read_lsi_status(card);
                    354:        /*
                    355:        printk(KERN_DEBUG LOGNAME 
                    356:               ": -- stat: %d  readpos: %d writepos: %d \n",
                    357:               stat,card->rbuf.read_pos,card->rbuf.write_pos);
                    358:        */
                    359:        if (stat & LSI_ARQ) {
                    360:                stat = read_lsi_status(card);
                    361:        }
                    362: 
                    363:        if (stat & LSI_READY){
                    364:                data = read_indexed_register(card, IIO_LSI_CONTROL);
                    365:                data |= RR;
                    366:                write_indexed_register(card, IIO_LSI_CONTROL, data);
                    367:                return 0;
                    368:        }
                    369: 
                    370:        if ((stat & LSI_ARQ) == 0) {
                    371:                size = DecoderGetBufferSpace(card);
                    372:                if (count > size) count = size & 0xfffffffc;
                    373:                if (count>=2048) count &=0xfffff800;
                    374:                count &=0xfffffffc;
1.5       mocm      375:               
1.4       rjkm      376:                if (!size &&
1.5       mocm      377:                    !card->DecoderOpen  ){
1.4       rjkm      378:                        printk(KERN_DEBUG LOGNAME 
                    379:                               ": -- PREPARE IT ALREADY\n");
                    380:                        Prepare(card);
1.5       mocm      381:                        card->startingV = 1;
                    382:                        card->startingA = 1;
1.4       rjkm      383:                }
1.5       mocm      384:                
                    385:                if (count > size) count = size & 0xfffffffc;
1.4       rjkm      386: 
1.5       mocm      387:                /*              printk(KERN_DEBUG LOGNAME 
1.4       rjkm      388:                       ": -- stat: %d  length: %d size: %d startV: %d startA: %d\n",
                    389:                       stat,count,size, card->startingV, card->startingA);
1.1       cvs       390:                */
                    391:                if (count) {
                    392:                        ring_read_direct(&(card->rbuf),
                    393:                                         link->io.BasePort1+DIO_LSI_STATUS, 
                    394:                                         count);
                    395:                    }
                    396:        } else {
                    397:                count = 0;
                    398:                //card->DMAABusy = 0;
                    399:        }
                    400: 
                    401:        return count;
                    402: }
                    403: 
                    404: 
                    405: u_char read_indexed_register(struct cvdv_cards * card, int addr)
                    406: {
                    407:        dev_link_t *link = &(((margi_info_t *) card->margi)->link);
                    408: 
                    409:        outb(addr, link->io.BasePort1 + DIO_CONTROL_INDEX);
                    410:        return (inb(link->io.BasePort1 + DIO_CONTROL_DATA));
                    411: }
                    412: 
                    413: 
                    414: void write_indexed_register(struct cvdv_cards *card, int addr, u_char data)
                    415: {
                    416:        dev_link_t *link = &(((margi_info_t *) card->margi)->link);
                    417: 
                    418:        outb(addr, link->io.BasePort1 + DIO_CONTROL_INDEX);
                    419:        outb(data, link->io.BasePort1 + DIO_CONTROL_DATA);
                    420: }
                    421: 
                    422: void WriteByte(struct cvdv_cards *card, int addr, u_char data)
                    423: {
                    424:        dev_link_t *link = &(((margi_info_t *) card->margi)->link);
                    425: 
                    426:        outb((u_char) (addr & 255),
                    427:             link->io.BasePort1 + DIO_LSI_INDEX_LOW);
                    428:        outb(((addr & 256) ? 1 : 0),
                    429:             link->io.BasePort1 + DIO_LSI_INDEX_HIGH);
                    430:        outb(data, link->io.BasePort1 + DIO_LSI_DATA);
                    431: }
                    432: 
                    433: u_char ReadByte(struct cvdv_cards *card, int addr)
                    434: {
                    435:        dev_link_t *link = &(((margi_info_t *) card->margi)->link);
                    436: 
                    437:        outb((u_char) (addr & 255),
                    438:             link->io.BasePort1 + DIO_LSI_INDEX_LOW);
                    439:        outb(((addr & 256) ? 1 : 0),
                    440:             link->io.BasePort1 + DIO_LSI_INDEX_HIGH);
                    441:        return inb(link->io.BasePort1 + DIO_LSI_DATA);
                    442: }
                    443: 
                    444: void MaskByte(struct cvdv_cards *card, int addr, u_char mask, u_char bits)
                    445: {
                    446:        WriteByte(card, addr, (ReadByte(card, addr) & ~(mask)) | (bits));
                    447: }
                    448: 
                    449: 
                    450: 
                    451: #define MAXWRITE 49000
                    452: #define MAX_COUNT 10
                    453: 
                    454: #ifdef USE_BH
                    455: struct cvdv_cards *bh_card;
                    456: 
                    457: static void do_margi_bh(void)
                    458: {
                    459:        struct cvdv_cards *card = bh_card;
                    460: #else
                    461: 
                    462: static void do_margi(struct cvdv_cards *card)
                    463: {
                    464: 
                    465: #endif
                    466:        int countA, countB;
                    467:        int try;
                    468: 
                    469:        countA = 0;
                    470:        countB = 0;
                    471: 
                    472:        card->currentType = 0;
                    473:        for ( try = 0; try < MAX_COUNT ;try++)
                    474:                if (countA < MAXWRITE){
                    475:                        int count = 0;
                    476:                        count = ringDMA(card);
                    477:                        countA += count;
                    478:                        if (!count) 
                    479:                                try=MAX_COUNT;
                    480:                } else break;
                    481: 
                    482: 
                    483: }
                    484: 
                    485: void L64014Intr(int irq, void *dev_id, struct pt_regs *regs)
                    486: {
                    487:        margi_info_t *margi = dev_id;
                    488:        struct cvdv_cards *card = &(margi->card);
                    489:        u_char dio_index, lsi_index_low, lsi_index_high;
                    490:        u8 control,mask,stat;
                    491:        int try;
1.5       mocm      492:        int count;
1.1       cvs       493: 
                    494:        //save registers
                    495:        dio_index = inb(margi->link.io.BasePort1 + DIO_CONTROL_INDEX);
                    496:        lsi_index_low = inb(margi->link.io.BasePort1 + DIO_LSI_INDEX_LOW);
                    497:        lsi_index_high =
                    498:            inb(margi->link.io.BasePort1 + DIO_LSI_INDEX_HIGH);
                    499: 
                    500:        control= read_indexed_register(card, IIO_IRQ_CONTROL);
                    501:        if (control & IRQ_EN){
                    502:                mask = 0;
                    503:                if ( control & DEC_EN ) mask |= DEC_INT;
                    504:                if ( control & VSYNC_EN ) mask |= VSYNC_INT;
                    505:                stat = read_indexed_register(card, IIO_IRQ_STATUS);
                    506:                try = 0;
                    507:                while ( (try++ < 100) && (stat & mask) ){                     
                    508:                        
                    509:                        if (stat & DEC_INT) {
                    510:                                write_indexed_register(card,IIO_IRQ_CONTROL,
                    511:                                                       control & (~DEC_EN));
                    512:                                write_indexed_register(card,IIO_IRQ_CONTROL,
                    513:                                                       control);
                    514:                                
                    515:                                if(card->use_ring){
                    516:                                        L64021Intr(card);
                    517:                                }
                    518:                        }
                    519:                        if (stat & VSYNC_INT) {
                    520:                                
                    521:                                write_indexed_register(card,IIO_IRQ_CONTROL,
                    522:                                                       control & (~VSYNC_EN));
                    523:                                write_indexed_register(card,IIO_IRQ_CONTROL,
                    524:                                                       control);
                    525:                                if(card->use_ring){
                    526:                                        L64021Intr(card);
                    527:                                }
1.5       mocm      528:                                count = ring_read_rest(&(card->rbuf));
                    529:                                if (count) card->DMAABusy=1;
1.1       cvs       530:                                if (card->DMAABusy){
                    531: 
                    532: #ifdef USE_BH
                    533:                                        bh_card = card;
                    534:                                        mark_bh(MARGI_BH);
                    535: #else 
                    536:                                        do_margi(card);
                    537: #endif
                    538:                }
                    539:                        }
                    540: 
                    541:                        stat = read_indexed_register(card, IIO_IRQ_STATUS);
                    542:                }
                    543:        }
                    544: 
                    545:        //load registers
                    546:        outb(dio_index, margi->link.io.BasePort1 + DIO_CONTROL_INDEX);
                    547:        outb(lsi_index_low, margi->link.io.BasePort1 + DIO_LSI_INDEX_LOW);
                    548:        outb(lsi_index_high,margi->link.io.BasePort1 + DIO_LSI_INDEX_HIGH);
                    549: }
                    550: 
                    551: int L64014RemoveIntr(struct cvdv_cards *card)
                    552: {
                    553:        printk(KERN_DEBUG LOGNAME ": -- L64014RemoveIntr\n");
                    554:        // Disable the IRQ's
                    555:        write_indexed_register(card, IIO_IRQ_CONTROL, 0x00);
                    556:        if (!card->IntInstalled)
                    557:                return 1;
                    558:        L64021RemoveIntr(card);
                    559:        return 0;
                    560: }
                    561: 
                    562: void l64020Reset(struct cvdv_cards *card){
                    563:        u8 data;
                    564:        
                    565:        
                    566:        data = read_indexed_register(card, IIO_LSI_CONTROL);
                    567:        data &= ~(RR | DR);
                    568:        write_indexed_register(card, IIO_LSI_CONTROL, data);
                    569:        mdelay(100);
                    570:        data = read_indexed_register(card, IIO_LSI_CONTROL);
                    571:        data |= DR;
                    572:        write_indexed_register(card, IIO_LSI_CONTROL, data);
                    573: 
                    574:        data = read_indexed_register(card,IIO_GPIO_PINS);
                    575:        data &= ~0x01;
                    576:        write_indexed_register(card,IIO_GPIO_PINS,data);
                    577:        data |= 0x01;
                    578:        write_indexed_register(card,IIO_GPIO_PINS,data);
                    579:        
                    580:        //write_indexed_register(card, IIO_LSI_CONTROL, DR);
                    581: }
                    582: 
                    583: int L64014Init(struct cvdv_cards *card)
                    584: {
                    585:        u16 testram[16];
                    586:        int i, err;
                    587: 
                    588:        printk(KERN_DEBUG LOGNAME ": -- L64014Init\n");
                    589:        card->videomode = VIDEO_MODE;
                    590: 
                    591:        /* Reset 64020 */
                    592:        write_indexed_register(card, IIO_GPIO_CONTROL, 0x01);
                    593:        l64020Reset(card);
                    594:        /* init GPIO */
                    595:        write_indexed_register(card, IIO_GPIO_CONTROL, 0x01);
                    596:        write_indexed_register(card, IIO_GPIO_PINS, 0xff);
                    597: 
                    598:        /* Set to PAL */
                    599:        write_indexed_register(card, IIO_VIDEO_CONTROL0, 0);
                    600:        write_indexed_register(card, IIO_VIDEO_CONTROL1, VMS_PAL);
                    601: 
                    602:        /* Set Audio freq */
                    603:        write_indexed_register(card, IIO_OSC_AUD, 0x12);
                    604: 
                    605:        write_indexed_register(card, CSS_COMMAND, 0x01);
                    606: 
                    607: 
                    608:        printk("CSID: %02x\n", I2CRead(card, 0, 0x3d));
                    609:        card->i2c_addr = I2CRead(card, 0, 0x0f);
                    610:        printk("I2CADDR: %02x\n", card->i2c_addr);
                    611: 
                    612:        I2CWrite(card, card->i2c_addr, CS_CONTROL0, 0x4a);
                    613:        I2CWrite(card, card->i2c_addr, CS_CONTROL1, 0x04);
                    614:        I2CWrite(card, card->i2c_addr, CS_SC_AMP, 0x15);
                    615:        I2CWrite(card, card->i2c_addr, CS_SC_SYNTH0, 0x96);
                    616:        I2CWrite(card, card->i2c_addr, CS_SC_SYNTH1, 0x15);
                    617:        I2CWrite(card, card->i2c_addr, CS_SC_SYNTH2, 0x13);
                    618:        I2CWrite(card, card->i2c_addr, CS_SC_SYNTH3, 0x54);
                    619: 
                    620:        I2CWrite(card, card->i2c_addr, CS_DAC, 0x87);
                    621:        I2CWrite(card, card->i2c_addr, CS_BKG_COL, 0x03);
                    622: 
                    623:        printk("Decoder Status: %d\n", read_lsi_status(card));
                    624:        printk("lsi stat %d\n", DecoderReadByte(card, 0x005));
                    625: 
                    626:        L64021Init(card);
                    627: 
                    628:        // Find out how much DRAM we have
1.5       mocm      629:        card->DRAMSize = 0x00100000;    // maximum size
1.1       cvs       630:        do {
                    631:                printk(KERN_DEBUG LOGNAME
                    632:                       ": Probing DRAM Size: 0x%08X (%d kByte) ... ",
                    633:                       card->DRAMSize, card->DRAMSize / 512);
                    634:                for (i = 0; i < 8; i++)
                    635:                        testram[i] = rnd(0x100) | (rnd(0x100) << 8);
                    636:                if (DRAMWriteWord(card, 0, 4, &testram[0], 0))
                    637:                        printk(KERN_DEBUG LOGNAME ": DRAM Write error.\n");
                    638:                if (DRAMWriteWord
                    639:                    (card, card->DRAMSize - 4, 4, &testram[4],
                    640:                     0)) printk(KERN_DEBUG LOGNAME
                    641:                                ": DRAM Write error.\n");
                    642:                if (DRAMReadWord(card, 0, 4, &testram[8], 0))
                    643:                        printk(KERN_DEBUG LOGNAME ": DRAM Read error.\n");
                    644:                if (DRAMReadWord
                    645:                    (card, card->DRAMSize - 4, 4, &testram[12],
                    646:                     0)) printk(KERN_DEBUG LOGNAME ": DRAM Read error.\n");
                    647:                err = 0;
                    648:                for (i = 0; (!err) && (i < 8); i++)
                    649:                        if (testram[i] != testram[i + 8])
                    650:                                err = i + 1;
                    651:                if (err) printk(" failed\n");
                    652:                else printk(" ok\n");
                    653:                /*
                    654:                if (err)
                    655:                        printk(KERN_DEBUG LOGNAME
                    656:                               ": DRAM compare error at cell %d: 0x%04X %04X %04X %04X->0x%04X %04X %04X %04X / 0x%04X %04X %04X %04X->0x%04X %04X %04X %04X\n",
                    657:                               err, testram[0], testram[1], testram[2],
                    658:                               testram[3], testram[8], testram[9],
                    659:                               testram[10], testram[11], testram[4],
                    660:                               testram[5], testram[6], testram[7],
                    661:                               testram[12], testram[13], testram[14],
                    662:                               testram[15]);
                    663:                */
                    664:                if (err)
                    665:                        card->DRAMSize >>= 1;
                    666:        } while (err && (card->DRAMSize >= 0x00100000));
                    667:        printk(KERN_INFO LOGNAME ": DRAM Size: 0x%08X (%d kByte)\n",
                    668:               card->DRAMSize, card->DRAMSize / 512);
                    669:        if (card->DRAMSize < 0x00100000) {      // minimum size
                    670:                printk(KERN_INFO LOGNAME
                    671:                       ": DRAM ERROR: Not enough memory on card!\n");
                    672:                return 1;
                    673:        }
                    674:        return 0;
                    675: }
                    676: 
                    677: 
                    678: void CardDeInit(struct cvdv_cards *card)
                    679: {
                    680:        CloseCard(card);
                    681:        MargiFlush(card);
                    682:        MargiFreeBuffers(card);
                    683:        L64014RemoveIntr(card);
1.4       rjkm      684:        card_init(card, 0);
1.1       cvs       685: }
                    686: 
                    687: 
                    688: static u_char read_lsi_status(struct cvdv_cards *card)
                    689: {
                    690:        margi_info_t *margi = (margi_info_t *) card->margi;
                    691:        return (inb(margi->link.io.BasePort1 + DIO_LSI_STATUS) & 15);
                    692: 
                    693: }
                    694: 
                    695: /*====================================================================*/
                    696: 
                    697: static void cs_error(client_handle_t handle, int func, int ret)
                    698: {
                    699:        error_info_t err = { func, ret };
                    700:        CardServices(ReportError, handle, &err);
                    701: }
                    702: 
                    703: /*======================================================================
                    704: 
                    705:     margi_attach() creates an "instance" of the driver, allocating
                    706:     local data structures for one device.  The device is registered
                    707:     with Card Services.
                    708: 
                    709:     The dev_link structure is initialized, but we don't actually
                    710:     configure the card at this point -- we wait until we receive a
                    711:     card insertion event.
                    712:     
                    713: ======================================================================*/
                    714: 
                    715: static dev_link_t *margi_attach(void)
                    716: {
                    717:        margi_info_t *local;
                    718:        dev_link_t *link;
                    719:        client_reg_t client_reg;
                    720:        int ret, i;
                    721: 
                    722:        DEBUG(0, "margi_attach()\n");
                    723: 
                    724:        for (i = 0; i < MAX_DEV; i++)
                    725:                if (dev_table[i] == NULL)
                    726:                        break;
                    727:        if (i == MAX_DEV) {
                    728:                printk(KERN_NOTICE "margi_cs: no devices available\n");
                    729:                return NULL;
                    730:        }
                    731: 
                    732:        /* Allocate space for private device-specific data */
                    733:        local = kmalloc(sizeof(margi_info_t), GFP_KERNEL);
                    734:        if (!local)
                    735:                return NULL;
                    736:        memset(local, 0, sizeof(margi_info_t));
                    737:        link = &local->link;
                    738:        link->priv = local;
                    739:        local->card.margi = (void *) local;
                    740:        dev_table[i] = link;
                    741: 
                    742:        /* Initialize the dev_link_t structure */
                    743:        link->release.function = &margi_release;
                    744:        link->release.data = (u_long) link;
                    745: 
                    746:        /* Interrupt setup */
                    747:        link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
                    748:        link->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID;
                    749:        if (irq_list[0] == -1)
                    750:                link->irq.IRQInfo2 = irq_mask;
                    751:        else
                    752:                for (i = 0; i < 4; i++)
                    753:                        link->irq.IRQInfo2 |= 1 << irq_list[i];
                    754:        link->irq.Handler = NULL;
                    755: 
                    756:        /*
                    757:           General socket configuration defaults can go here.  In this
                    758:           client, we assume very little, and rely on the CIS for almost
                    759:           everything.  In most clients, many details (i.e., number, sizes,
                    760:           and attributes of IO windows) are fixed by the nature of the
                    761:           device, and can be hard-wired here.
                    762:         */
                    763:        link->conf.Attributes = 0;
                    764:        link->conf.Vcc = 50;
                    765:        link->conf.IntType = INT_MEMORY_AND_IO;
                    766: 
                    767:        /* Register with Card Services */
                    768:        link->next = dev_list;
                    769:        dev_list = link;
                    770:        client_reg.dev_info = &dev_info;
                    771:        client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
                    772:        client_reg.EventMask =
                    773:            CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
                    774:            CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
                    775:            CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
                    776:        client_reg.event_handler = &margi_event;
                    777:        client_reg.Version = 0x0210;
                    778:        client_reg.event_callback_args.client_data = link;
                    779:        ret = CardServices(RegisterClient, &link->handle, &client_reg);
                    780:        if (ret != CS_SUCCESS) {
                    781:                cs_error(link->handle, RegisterClient, ret);
                    782:                margi_detach(link);
                    783:                return NULL;
                    784:        }
                    785: 
                    786:        return link;
                    787: }                              /* margi_attach */
                    788: 
                    789: /*======================================================================
                    790: 
                    791:     This deletes a driver "instance".  The device is de-registered
                    792:     with Card Services.  If it has been released, all local data
                    793:     structures are freed.  Otherwise, the structures will be freed
                    794:     when the device is released.
                    795: 
                    796: ======================================================================*/
                    797: 
                    798: static void margi_detach(dev_link_t * link)
                    799: {
                    800:        dev_link_t **linkp;
                    801: 
                    802:        int nd;
                    803: 
                    804:        DEBUG(0, "margi_detach(0x%p)\n", link);
                    805: 
                    806:        for (nd = 0; nd < MAX_DEV; nd++)
                    807:                if (dev_table[nd] == link)
                    808:                        break;
                    809:        if (nd == MAX_DEV)
                    810:                return;
                    811: 
                    812:        /* Locate device structure */
                    813:        for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
                    814:                if (*linkp == link)
                    815:                        break;
                    816:        if (*linkp == NULL)
                    817:                return;
                    818: 
                    819:        /*
                    820:           If the device is currently configured and active, we won't
                    821:           actually delete it yet.  Instead, it is marked so that when
                    822:           the release() function is called, that will trigger a proper
                    823:           detach().
                    824:         */
                    825:        if (link->state & DEV_CONFIG) {
                    826: #ifdef PCMCIA_DEBUG
                    827:                printk(KERN_DEBUG "margi_cs: detach postponed, '%s' "
                    828:                       "still locked\n", link->dev->dev_name);
                    829: #endif
                    830:                link->state |= DEV_STALE_LINK;
                    831:                return;
                    832:        }
                    833: 
                    834:        /* Break the link with Card Services */
                    835:        if (link->handle)
                    836:                CardServices(DeregisterClient, link->handle);
                    837: 
                    838:        /* Unlink device structure, and free it */
                    839:        *linkp = link->next;
                    840:        /* This points to the parent struct cvdv_cards struct */
                    841:        dev_table[nd] = NULL;
                    842: 
                    843:        kfree(link->priv);
                    844: 
                    845: }                              /* margi_detach */
                    846: 
                    847: /*======================================================================
                    848: 
                    849:     margi_config() is scheduled to run after a CARD_INSERTION event
                    850:     is received, to configure the PCMCIA socket, and to make the
                    851:     device available to the system.
                    852:     
                    853: ======================================================================*/
                    854: 
                    855: #define CS_CHECK(fn, args...) \
                    856: while ((last_ret=CardServices(last_fn=(fn),args))!=0) goto cs_failed
                    857: 
                    858: #define CFG_CHECK(fn, args...) \
                    859: if (CardServices(fn, args) != 0) goto next_entry
                    860: 
                    861: static void margi_config(dev_link_t * link)
                    862: {
                    863:        client_handle_t handle = link->handle;
                    864:        margi_info_t *dev = link->priv;
                    865:        struct cvdv_cards *card = &(dev->card);
                    866:        tuple_t tuple;
                    867:        cisparse_t parse;
                    868:        int last_fn, last_ret, i;
                    869:        u_char buf[64];
                    870:        config_info_t conf;
                    871:        win_req_t req;
                    872:        memreq_t map;
                    873:        int minor = 0;
                    874: 
                    875:        DEBUG(0, "margi_config(0x%p)\n", link);
                    876: 
                    877:        /*
                    878:           This reads the card's CONFIG tuple to find its configuration
                    879:           registers.
                    880:         */
                    881:        tuple.DesiredTuple = CISTPL_CONFIG;
                    882:        tuple.Attributes = 0;
                    883:        tuple.TupleData = buf;
                    884:        tuple.TupleDataMax = sizeof(buf);
                    885:        tuple.TupleOffset = 0;
                    886:        CS_CHECK(GetFirstTuple, handle, &tuple);
                    887:        CS_CHECK(GetTupleData, handle, &tuple);
                    888:        CS_CHECK(ParseTuple, handle, &tuple, &parse);
                    889:        link->conf.ConfigBase = parse.config.base;
                    890:        link->conf.Present = parse.config.rmask[0];
                    891: 
                    892:        /* Configure card */
                    893:        link->state |= DEV_CONFIG;
                    894: 
                    895:        /* Look up the current Vcc */
                    896:        CS_CHECK(GetConfigurationInfo, handle, &conf);
                    897:        link->conf.Vcc = conf.Vcc;
                    898: 
                    899:        /*
                    900:           In this loop, we scan the CIS for configuration table entries,
                    901:           each of which describes a valid card configuration, including
                    902:           voltage, IO window, memory window, and interrupt settings.
                    903: 
                    904:           We make no assumptions about the card to be configured: we use
                    905:           just the information available in the CIS.  In an ideal world,
                    906:           this would work for any PCMCIA card, but it requires a complete
                    907:           and accurate CIS.  In practice, a driver usually "knows" most of
                    908:           these things without consulting the CIS, and most client drivers
                    909:           will only use the CIS to fill in implementation-defined details.
                    910:         */
                    911:        tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
                    912:        CS_CHECK(GetFirstTuple, handle, &tuple);
                    913:        while (1) {
                    914:                cistpl_cftable_entry_t dflt = { 0 };
                    915:                cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
                    916:                CFG_CHECK(GetTupleData, handle, &tuple);
                    917:                CFG_CHECK(ParseTuple, handle, &tuple, &parse);
                    918: 
                    919:                if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
                    920:                        dflt = *cfg;
                    921:                if (cfg->index == 0)
                    922:                        goto next_entry;
                    923:                link->conf.ConfigIndex = cfg->index;
                    924: 
                    925:                /* Does this card need audio output? */
                    926:                if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
                    927:                        link->conf.Attributes |= CONF_ENABLE_SPKR;
                    928:                        link->conf.Status = CCSR_AUDIO_ENA;
                    929:                }
                    930: 
                    931:                /* Use power settings for Vcc and Vpp if present */
                    932:                /*  Note that the CIS values need to be rescaled */
                    933:                if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
                    934:                        if (conf.Vcc !=
                    935:                            cfg->vcc.param[CISTPL_POWER_VNOM] /
                    936:                            10000) goto next_entry;
                    937:                } else if (dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) {
                    938:                        if (conf.Vcc !=
                    939:                            dflt.vcc.param[CISTPL_POWER_VNOM] /
                    940:                            10000) goto next_entry;
                    941:                }
                    942: 
                    943:                if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
                    944:                        link->conf.Vpp1 = link->conf.Vpp2 =
                    945:                            cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
                    946:                else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
                    947:                        link->conf.Vpp1 = link->conf.Vpp2 =
                    948:                            dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
                    949: 
                    950:                /* Do we need to allocate an interrupt? */
                    951:                //      if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1)
                    952:                //link->conf.Attributes |= CONF_ENABLE_IRQ;
                    953:                /*
                    954:                   Allocate an interrupt line.  Note that this does not assign a
                    955:                   handler to the interrupt, unless the 'Handler' member of the
                    956:                   irq structure is initialized.
                    957:                 */
                    958: 
                    959:                link->irq.Attributes =
                    960:                  IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
                    961:                link->irq.Handler = &L64014Intr;
                    962:                link->irq.Instance = link;
                    963:                link->conf.Attributes |= CONF_ENABLE_IRQ;
                    964: 
                    965: #ifdef USE_BH
                    966:                init_bh(MARGI_BH, do_margi_bh);
                    967: #endif
                    968:                if (link->conf.Attributes & CONF_ENABLE_IRQ)
                    969:                        CS_CHECK(RequestIRQ, link->handle, &link->irq);
                    970: 
                    971:                /* IO window settings */
                    972:                link->io.NumPorts1 = link->io.NumPorts2 = 0;
                    973:                if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
                    974:                        cistpl_io_t *io =
                    975:                            (cfg->io.nwin) ? &cfg->io : &dflt.io;
                    976:                        link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
                    977:                        if (!(io->flags & CISTPL_IO_8BIT))
                    978:                                link->io.Attributes1 =
                    979:                                    IO_DATA_PATH_WIDTH_16;
                    980:                        if (!(io->flags & CISTPL_IO_16BIT))
                    981:                                link->io.Attributes1 =
                    982:                                    IO_DATA_PATH_WIDTH_8;
                    983:                        link->io.IOAddrLines =
                    984:                            io->flags & CISTPL_IO_LINES_MASK;
                    985:                        link->io.BasePort1 = io->win[0].base;
                    986:                        link->io.NumPorts1 = io->win[0].len;
                    987:                        if (io->nwin > 1) {
                    988:                                link->io.Attributes2 =
                    989:                                    link->io.Attributes1;
                    990:                                link->io.BasePort2 = io->win[1].base;
                    991:                                link->io.NumPorts2 = io->win[1].len;
                    992:                        }
                    993:                }
                    994: 
                    995:                /* This reserves IO space but doesn't actually enable it */
                    996:                CFG_CHECK(RequestIO, link->handle, &link->io);
                    997: 
                    998:                /*
                    999:                   Now set up a common memory window, if needed.  There is room
                   1000:                   in the dev_link_t structure for one memory window handle,
                   1001:                   but if the base addresses need to be saved, or if multiple
                   1002:                   windows are needed, the info should go in the private data
                   1003:                   structure for this device.
                   1004: 
                   1005:                   Note that the memory window base is a physical address, and
                   1006:                   needs to be mapped to virtual space with ioremap() before it
                   1007:                   is used.
                   1008:                 */
                   1009:                if ((cfg->mem.nwin > 0) || (dflt.mem.nwin > 0)) {
                   1010:                        cistpl_mem_t *mem =
                   1011:                            (cfg->mem.nwin) ? &cfg->mem : &dflt.mem;
                   1012:                        req.Attributes =
                   1013:                            WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_CM;
                   1014:                        req.Attributes |= WIN_ENABLE;
                   1015:                        req.Base = mem->win[0].host_addr;
                   1016:                        req.Size = mem->win[0].len;
                   1017:                        req.AccessSpeed = 0;
                   1018:                        link->win = (window_handle_t) link->handle;
                   1019:                        CFG_CHECK(RequestWindow, &link->win, &req);
                   1020:                        map.Page = 0;
                   1021:                        map.CardOffset = mem->win[0].card_addr;
                   1022:                        CFG_CHECK(MapMemPage, link->win, &map);
                   1023:                }
                   1024:                /* If we got this far, we're cool! */
                   1025:                break;
                   1026:                
                   1027:        next_entry:
                   1028:                CS_CHECK(GetNextTuple, handle, &tuple);
                   1029:        }
                   1030: 
                   1031:        /*
                   1032:           This actually configures the PCMCIA socket -- setting up
                   1033:           the I/O windows and the interrupt mapping, and putting the
                   1034:           card and host interface into "Memory and IO" mode.
                   1035:         */
                   1036:        CS_CHECK(RequestConfiguration, link->handle, &link->conf);
                   1037: 
                   1038:        /*
                   1039:           We can release the IO port allocations here, if some other
                   1040:           driver for the card is going to loaded, and will expect the
                   1041:           ports to be available.
                   1042:         */
                   1043:        if (free_ports) {
                   1044:                if (link->io.BasePort1)
                   1045:                        release_region(link->io.BasePort1,
                   1046:                                       link->io.NumPorts1);
                   1047:                if (link->io.BasePort2)
                   1048:                        release_region(link->io.BasePort2,
                   1049:                                       link->io.NumPorts2);
                   1050:        }
                   1051: 
                   1052:        /*
                   1053:           At this point, the dev_node_t structure(s) need to be
                   1054:           initialized and arranged in a linked list at link->dev.
                   1055:         */
                   1056: 
                   1057:        first_card = card;
                   1058:        minor=0;
                   1059:        card->next = NULL;
                   1060:        card_init(card, minor);
                   1061:        if ((i = register_chrdev(CVDV_MAJOR, CVDV_PROCNAME, &cvdv_fileops))
                   1062:            >= 0) {
                   1063:                major_device_number = ((i) ? i : CVDV_MAJOR);
                   1064:                printk(KERN_INFO LOGNAME
                   1065:                       ": Char-device with major number %d installed\n",
                   1066:                       major_device_number);
                   1067:        } else {
                   1068:                printk(KERN_ERR LOGNAME
                   1069:                       ": ERROR: Failed to install Char-device %d, error %d\n",
                   1070:                       CVDV_MAJOR, i);
                   1071:        }
                   1072:        sprintf(dev->node.dev_name, "margi");
                   1073:        dev->node.major = major_device_number;
                   1074:        dev->node.minor = minor;
                   1075:        link->dev = &dev->node;
                   1076: 
                   1077:        /* Finally, report what we've done */
                   1078:        printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d",
                   1079:               dev->node.dev_name, link->conf.ConfigIndex,
                   1080:               link->conf.Vcc / 10, link->conf.Vcc % 10);
                   1081:        if (link->conf.Vpp1)
                   1082:                printk(", Vpp %d.%d", link->conf.Vpp1 / 10,
                   1083:                       link->conf.Vpp1 % 10);
                   1084:        if (link->conf.Attributes & CONF_ENABLE_IRQ)
                   1085:                printk(", irq %d", link->irq.AssignedIRQ);
                   1086:        if (link->io.NumPorts1)
                   1087:                printk(", io 0x%04x-0x%04x", link->io.BasePort1,
                   1088:                       link->io.BasePort1 + link->io.NumPorts1 - 1);
                   1089:        if (link->io.NumPorts2)
                   1090:                printk(" & 0x%04x-0x%04x", link->io.BasePort2,
                   1091:                       link->io.BasePort2 + link->io.NumPorts2 - 1);
                   1092:        if (link->win)
                   1093:                printk(", mem 0x%06lx-0x%06lx", req.Base,
                   1094:                       req.Base + req.Size - 1);
                   1095:        printk("\n");
                   1096: 
                   1097:        link->state &= ~DEV_CONFIG_PENDING;
                   1098:        if (0xdd == read_indexed_register(card, IIO_ID)) {
                   1099:                printk("L64014 Version %d in mode %d detected\n",
                   1100:                       (read_indexed_register(card, IIO_MODE) & 248) >> 3,
                   1101:                       read_indexed_register(card, IIO_MODE) & 7);
                   1102:                write_indexed_register(card, IIO_GPIO_CONTROL, 0x07);
                   1103: 
                   1104:                L64014Init(card);
                   1105: 
                   1106:                // default: color bars
                   1107:                VideoSetBackground(card, 1, 0, 0, 0);   // black
                   1108:                SetVideoSystem(card);
                   1109:                minorlist[minor] = card;        // fast access for the char driver
                   1110: 
                   1111: 
                   1112:                /*enable L64014 IRQ */
                   1113:                write_indexed_register(card, IIO_IRQ_CONTROL,
                   1114:                                       IRQ_POL | IRQ_EN | VSYNC_EN);
                   1115: //             write_indexed_register(card, IIO_IRQ_CONTROL, 0x24);
1.6     ! mocm     1116:                OSDOpen(card, 50, 50, 150, 150, 2, 1);
        !          1117:                OSDTest(card);
1.1       cvs      1118:        }
                   1119:        return;
                   1120: 
                   1121:       cs_failed:
                   1122:        cs_error(link->handle, last_fn, last_ret);
                   1123:        margi_release((u_long) link);
                   1124: 
                   1125: }                              /* margi_config */
                   1126: 
                   1127: /*======================================================================
                   1128: 
                   1129:     After a card is removed, margi_release() will unregister the
                   1130:     device, and release the PCMCIA configuration.  If the device is
                   1131:     still open, this will be postponed until it is closed.
                   1132:     
                   1133: ======================================================================*/
                   1134: 
                   1135: static void margi_release(u_long arg)
                   1136: {
                   1137:        dev_link_t *link = (dev_link_t *) arg;
                   1138:        margi_info_t *dev = link->priv;
                   1139:        struct cvdv_cards *card = &(dev->card);
                   1140: 
                   1141:        DEBUG(0, "margi_release(0x%p)\n", link);
                   1142:        /*
                   1143:           If the device is currently in use, we won't release until it
                   1144:           is actually closed, because until then, we can't be sure that
                   1145:           no one will try to access the device or its data structures.
                   1146:         */
                   1147:        if (link->open) {
                   1148:                DEBUG(1, "margi_cs: release postponed, '%s' still open\n",
                   1149:                      link->dev->dev_name);
                   1150:                link->state |= DEV_STALE_CONFIG;
                   1151:                return;
                   1152:        }
                   1153: 
                   1154:        /* Unlink the device chain */
                   1155:        link->dev = NULL;
                   1156: 
                   1157:        /*
                   1158:           In a normal driver, additional code may be needed to release
                   1159:           other kernel data structures associated with this device. 
                   1160:         */
                   1161: 
                   1162:        printk(KERN_INFO LOGNAME ": Unloading device driver\n");
                   1163:        if (major_device_number)
                   1164:                unregister_chrdev(major_device_number, CVDV_PROCNAME);
                   1165:        CardDeInit(card);
                   1166: 
                   1167: #ifdef USE_BH
                   1168:        remove_bh(MARGI_BH);
                   1169: #endif
                   1170:        mdelay(100);
                   1171:        /* Don't bother checking to see if these succeed or not */
                   1172:        if (link->win)
                   1173:          CardServices(ReleaseWindow, link->win);
                   1174:        CardServices(ReleaseConfiguration, link->handle);
                   1175:        if (link->io.NumPorts1)
                   1176:          CardServices(ReleaseIO, link->handle, &link->io);
                   1177:        if (link->irq.AssignedIRQ)
                   1178:          CardServices(ReleaseIRQ, link->handle, &link->irq);
                   1179:        link->state &= ~DEV_CONFIG;
                   1180: 
                   1181:        if (link->state & DEV_STALE_LINK)
                   1182:                margi_detach(link);
                   1183: 
                   1184: }                              /* margi_release */
                   1185: 
                   1186: /*======================================================================
                   1187: 
                   1188:     The card status event handler.  Mostly, this schedules other
                   1189:     stuff to run after an event is received.
                   1190: 
                   1191:     When a CARD_REMOVAL event is received, we immediately set a
                   1192:     private flag to block future accesses to this device.  All the
                   1193:     functions that actually access the device should check this flag
                   1194:     to make sure the card is still present.
                   1195:     
                   1196: ======================================================================*/
                   1197: 
                   1198: static int margi_event(event_t event, int priority,
                   1199:                       event_callback_args_t * args)
                   1200: {
                   1201:        dev_link_t *link = args->client_data;
                   1202:        margi_info_t *dev = link->priv;
                   1203: 
                   1204:        DEBUG(1, "margi_event(0x%06x)\n", event);
                   1205: 
                   1206:        switch (event) {
                   1207:        case CS_EVENT_CARD_REMOVAL:
                   1208:                link->state &= ~DEV_PRESENT;
                   1209:                if (link->state & DEV_CONFIG) {
                   1210:                        ((margi_info_t *) link->priv)->stop = 1;
                   1211:                        link->release.expires = jiffies + HZ / 20;
                   1212:                        add_timer(&link->release);
                   1213:                }
                   1214:                break;
                   1215:        case CS_EVENT_CARD_INSERTION:
                   1216:                link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
                   1217:                dev->card.bus = args->bus;
                   1218:                margi_config(link);
                   1219:                break;
                   1220:        case CS_EVENT_PM_SUSPEND:
                   1221:                link->state |= DEV_SUSPEND;
                   1222:                /* Fall through... */
                   1223:        case CS_EVENT_RESET_PHYSICAL:
                   1224:                /* Mark the device as stopped, to block IO until later */
                   1225:                dev->stop = 1;
                   1226:                if (link->state & DEV_CONFIG)
                   1227:                        CardServices(ReleaseConfiguration, link->handle);
                   1228:                break;
                   1229:        case CS_EVENT_PM_RESUME:
                   1230:                link->state &= ~DEV_SUSPEND;
                   1231:                /* Fall through... */
                   1232:        case CS_EVENT_CARD_RESET:
                   1233:                if (link->state & DEV_CONFIG)
                   1234:                        CardServices(RequestConfiguration, link->handle,
                   1235:                                     &link->conf);
                   1236:                dev->stop = 0;
                   1237:                /*
                   1238:                   In a normal driver, additional code may go here to restore
                   1239:                   the device state and restart IO. 
                   1240:                 */
                   1241:                break;
                   1242:        }
                   1243:        return 0;
                   1244: }                              /* margi_event */
                   1245: 
                   1246: /*====================================================================*/
                   1247: 
                   1248: static int __init init_margi_cs(void)
                   1249: {
                   1250:        servinfo_t serv;
                   1251:        DEBUG(0, "%s\n", version);
                   1252:        CardServices(GetCardServicesInfo, &serv);
                   1253:        if (serv.Revision != CS_RELEASE_CODE) {
                   1254:                printk(KERN_NOTICE "margi_cs: Card Services release "
                   1255:                       "does not match!\n");
                   1256:                return -1;
                   1257:        }
                   1258:        register_pccard_driver(&dev_info, &margi_attach, &margi_detach);
                   1259:        return 0;
                   1260: }
                   1261: 
                   1262: static void __exit exit_margi_cs(void)
                   1263: {
                   1264:        DEBUG(0, "margi_cs: unloading\n");
                   1265:        unregister_pccard_driver(&dev_info);
                   1266:        while (dev_list != NULL) {
                   1267:                if (dev_list->state & DEV_CONFIG)
                   1268:                        margi_release((u_long) dev_list);
                   1269:                margi_detach(dev_list);
                   1270:        }
                   1271: }
                   1272: 
                   1273: module_init(init_margi_cs);
                   1274: module_exit(exit_margi_cs);

LinuxTV legacy CVS <linuxtv.org/cvs>