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