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