aboutsummaryrefslogblamecommitdiffstats
path: root/drivers/net/macmace.c
blob: 79a6fc1397574caad90ba72ccd617a60cb4f28e7 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710





































































































































































































































































































































































































































































































































































































































































































































                                                                                                             
/*
 *	Driver for the Macintosh 68K onboard MACE controller with PSC
 *	driven DMA. The MACE driver code is derived from mace.c. The
 *	Mac68k theory of operation is courtesy of the MacBSD wizards.
 *
 *	This program is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU General Public License
 *	as published by the Free Software Foundation; either version
 *	2 of the License, or (at your option) any later version.
 *
 *	Copyright (C) 1996 Paul Mackerras.
 *	Copyright (C) 1998 Alan Cox <alan@redhat.com>
 *
 *	Modified heavily by Joshua M. Thompson based on Dave Huang's NetBSD driver
 */


#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/delay.h>
#include <linux/string.h>
#include <linux/crc32.h>
#include <asm/io.h>
#include <asm/pgtable.h>
#include <asm/irq.h>
#include <asm/macintosh.h>
#include <asm/macints.h>
#include <asm/mac_psc.h>
#include <asm/page.h>
#include "mace.h"

#define N_TX_RING	1
#define N_RX_RING	8
#define N_RX_PAGES	((N_RX_RING * 0x0800 + PAGE_SIZE - 1) / PAGE_SIZE)
#define TX_TIMEOUT	HZ

/* Bits in transmit DMA status */
#define TX_DMA_ERR	0x80

/* The MACE is simply wired down on a Mac68K box */

#define MACE_BASE	(void *)(0x50F1C000)
#define MACE_PROM	(void *)(0x50F08001)

struct mace_data {
	volatile struct mace *mace;
	volatile unsigned char *tx_ring;
	volatile unsigned char *tx_ring_phys;
	volatile unsigned char *rx_ring;
	volatile unsigned char *rx_ring_phys;
	int dma_intr;
	struct net_device_stats stats;
	int rx_slot, rx_tail;
	int tx_slot, tx_sloti, tx_count;
};

struct mace_frame {
	u16	len;
	u16	status;
	u16	rntpc;
	u16	rcvcc;
	u32	pad1;
	u32	pad2;
	u8	data[1];	
	/* And frame continues.. */
};

#define PRIV_BYTES	sizeof(struct mace_data)

extern void psc_debug_dump(void);

static int mace_open(struct net_device *dev);
static int mace_close(struct net_device *dev);
static int mace_xmit_start(struct sk_buff *skb, struct net_device *dev);
static struct net_device_stats *mace_stats(struct net_device *dev);
static void mace_set_multicast(struct net_device *dev);
static int mace_set_address(struct net_device *dev, void *addr);
static irqreturn_t mace_interrupt(int irq, void *dev_id, struct pt_regs *regs);
static irqreturn_t mace_dma_intr(int irq, void *dev_id, struct pt_regs *regs);
static void mace_tx_timeout(struct net_device *dev);

/* Bit-reverse one byte of an ethernet hardware address. */

static int bitrev(int b)
{
	int d = 0, i;

	for (i = 0; i < 8; ++i, b >>= 1) {
		d = (d << 1) | (b & 1);
	}

	return d;
}

/*
 * Load a receive DMA channel with a base address and ring length
 */

static void mace_load_rxdma_base(struct net_device *dev, int set)
{
	struct mace_data *mp = (struct mace_data *) dev->priv;

	psc_write_word(PSC_ENETRD_CMD + set, 0x0100);
	psc_write_long(PSC_ENETRD_ADDR + set, (u32) mp->rx_ring_phys);
	psc_write_long(PSC_ENETRD_LEN + set, N_RX_RING);
	psc_write_word(PSC_ENETRD_CMD + set, 0x9800);
	mp->rx_tail = 0;
}

/*
 * Reset the receive DMA subsystem
 */

static void mace_rxdma_reset(struct net_device *dev)
{
	struct mace_data *mp = (struct mace_data *) dev->priv;
	volatile struct mace *mace = mp->mace;
	u8 maccc = mace->maccc;
	
	mace->maccc = maccc & ~ENRCV;
	
	psc_write_word(PSC_ENETRD_CTL, 0x8800);
	mace_load_rxdma_base(dev, 0x00);
	psc_write_word(PSC_ENETRD_CTL, 0x0400);
	
	psc_write_word(PSC_ENETRD_CTL, 0x8800);
	mace_load_rxdma_base(dev, 0x10);
	psc_write_word(PSC_ENETRD_CTL, 0x0400);
	
	mace->maccc = maccc;
	mp->rx_slot = 0;

	psc_write_word(PSC_ENETRD_CMD + PSC_SET0, 0x9800);
	psc_write_word(PSC_ENETRD_CMD + PSC_SET1, 0x9800);
}

/*
 * Reset the transmit DMA subsystem
 */
 
static void mace_txdma_reset(struct net_device *dev)
{
	struct mace_data *mp = (struct mace_data *) dev->priv;
	volatile struct mace *mace = mp->mace;
	u8 maccc;

	psc_write_word(PSC_ENETWR_CTL, 0x8800);

	maccc = mace->maccc;
	mace->maccc = maccc & ~ENXMT;

	mp->tx_slot = mp->tx_sloti = 0;
	mp->tx_count = N_TX_RING;

	psc_write_word(PSC_ENETWR_CTL, 0x0400);
	mace->maccc = maccc;
}

/*
 * Disable DMA
 */
 
static void mace_dma_off(struct net_device *dev)
{
	psc_write_word(PSC_ENETRD_CTL, 0x8800);
	psc_write_word(PSC_ENETRD_CTL, 0x1000);
	psc_write_word(PSC_ENETRD_CMD + PSC_SET0, 0x1100);
	psc_write_word(PSC_ENETRD_CMD + PSC_SET1, 0x1100);

	psc_write_word(PSC_ENETWR_CTL, 0x8800);
	psc_write_word(PSC_ENETWR_CTL, 0x1000);
	psc_write_word(PSC_ENETWR_CMD + PSC_SET0, 0x1100);
	psc_write_word(PSC_ENETWR_CMD + PSC_SET1, 0x1100);
}

/*
 * Not really much of a probe. The hardware table tells us if this
 * model of Macintrash has a MACE (AV macintoshes)
 */
 
struct net_device *mace_probe(int unit)
{
	int j;
	struct mace_data *mp;
	unsigned char *addr;
	struct net_device *dev;
	unsigned char checksum = 0;
	static int found = 0;
	int err;
	
	if (found || macintosh_config->ether_type != MAC_ETHER_MACE)
		return ERR_PTR(-ENODEV);

	found = 1;	/* prevent 'finding' one on every device probe */

	dev = alloc_etherdev(PRIV_BYTES);
	if (!dev)
		return ERR_PTR(-ENOMEM);

	if (unit >= 0)
		sprintf(dev->name, "eth%d", unit);

	mp = (struct mace_data *) dev->priv;
	dev->base_addr = (u32)MACE_BASE;
	mp->mace = (volatile struct mace *) MACE_BASE;
	
	dev->irq = IRQ_MAC_MACE;
	mp->dma_intr = IRQ_MAC_MACE_DMA;

	/*
	 * The PROM contains 8 bytes which total 0xFF when XOR'd
	 * together. Due to the usual peculiar apple brain damage
	 * the bytes are spaced out in a strange boundary and the
	 * bits are reversed.
	 */

	addr = (void *)MACE_PROM;
		 
	for (j = 0; j < 6; ++j) {
		u8 v=bitrev(addr[j<<4]);
		checksum ^= v;
		dev->dev_addr[j] = v;
	}
	for (; j < 8; ++j) {
		checksum ^= bitrev(addr[j<<4]);
	}
	
	if (checksum != 0xFF) {
		free_netdev(dev);
		return ERR_PTR(-ENODEV);
	}

	memset(&mp->stats, 0, sizeof(mp->stats));

	dev->open		= mace_open;
	dev->stop		= mace_close;
	dev->hard_start_xmit	= mace_xmit_start;
	dev->tx_timeout		= mace_tx_timeout;
	dev->watchdog_timeo	= TX_TIMEOUT;
	dev->get_stats		= mace_stats;
	dev->set_multicast_list	= mace_set_multicast;
	dev->set_mac_address	= mace_set_address;

	printk(KERN_INFO "%s: 68K MACE, hardware address %.2X", dev->name, dev->dev_addr[0]);
	for (j = 1 ; j < 6 ; j++) printk(":%.2X", dev->dev_addr[j]);
	printk("\n");

	err = register_netdev(dev);
	if (!err)
		return dev;

	free_netdev(dev);
	return ERR_PTR(err);
}

/*
 * Load the address on a mace controller.
 */

static int mace_set_address(struct net_device *dev, void *addr)
{
	unsigned char *p = addr;
	struct mace_data *mp = (struct mace_data *) dev->priv;
	volatile struct mace *mb = mp->mace;
	int i;
	unsigned long flags;
	u8 maccc;

	local_irq_save(flags);

	maccc = mb->maccc;

	/* load up the hardware address */
	mb->iac = ADDRCHG | PHYADDR;
	while ((mb->iac & ADDRCHG) != 0);
	
	for (i = 0; i < 6; ++i) {
		mb->padr = dev->dev_addr[i] = p[i];
	}

	mb->maccc = maccc;
	local_irq_restore(flags);

	return 0;
}

/*
 * Open the Macintosh MACE. Most of this is playing with the DMA
 * engine. The ethernet chip is quite friendly.
 */
 
static int mace_open(struct net_device *dev)
{
	struct mace_data *mp = (struct mace_data *) dev->priv;
	volatile struct mace *mb = mp->mace;
#if 0
	int i;

	i = 200;
	while (--i) {
		mb->biucc = SWRST;
		if (mb->biucc & SWRST) {
			udelay(10);
			continue;
		}
		break;
	}
	if (!i) {
		printk(KERN_ERR "%s: software reset failed!!\n", dev->name);
		return -EAGAIN;
	}
#endif

	mb->biucc = XMTSP_64;
	mb->fifocc = XMTFW_16 | RCVFW_64 | XMTFWU | RCVFWU | XMTBRST | RCVBRST;
	mb->xmtfc = AUTO_PAD_XMIT;
	mb->plscc = PORTSEL_AUI;
	/* mb->utr = RTRD; */

	if (request_irq(dev->irq, mace_interrupt, 0, dev->name, dev)) {
		printk(KERN_ERR "%s: can't get irq %d\n", dev->name, dev->irq);
		return -EAGAIN;
	}
	if (request_irq(mp->dma_intr, mace_dma_intr, 0, dev->name, dev)) {
		printk(KERN_ERR "%s: can't get irq %d\n", dev->name, mp->dma_intr);
		free_irq(dev->irq, dev);
		return -EAGAIN;
	}

	/* Allocate the DMA ring buffers */

	mp->rx_ring = (void *) __get_free_pages(GFP_KERNEL | GFP_DMA, N_RX_PAGES);
	mp->tx_ring = (void *) __get_free_pages(GFP_KERNEL | GFP_DMA, 0);
	
	if (mp->tx_ring==NULL || mp->rx_ring==NULL) {
		if (mp->rx_ring) free_pages((u32) mp->rx_ring, N_RX_PAGES);
		if (mp->tx_ring) free_pages((u32) mp->tx_ring, 0);
		free_irq(dev->irq, dev);
		free_irq(mp->dma_intr, dev);
		printk(KERN_ERR "%s: unable to allocate DMA buffers\n", dev->name);
		return -ENOMEM;
	}

	mp->rx_ring_phys = (unsigned char *) virt_to_bus((void *)mp->rx_ring);
	mp->tx_ring_phys = (unsigned char *) virt_to_bus((void *)mp->tx_ring);

	/* We want the Rx buffer to be uncached and the Tx buffer to be writethrough */

	kernel_set_cachemode((void *)mp->rx_ring, N_RX_PAGES * PAGE_SIZE, IOMAP_NOCACHE_NONSER);	
	kernel_set_cachemode((void *)mp->tx_ring, PAGE_SIZE, IOMAP_WRITETHROUGH);

	mace_dma_off(dev);

	/* Not sure what these do */

	psc_write_word(PSC_ENETWR_CTL, 0x9000);
	psc_write_word(PSC_ENETRD_CTL, 0x9000);
	psc_write_word(PSC_ENETWR_CTL, 0x0400);
	psc_write_word(PSC_ENETRD_CTL, 0x0400);

#if 0
	/* load up the hardware address */
	
	mb->iac = ADDRCHG | PHYADDR;
	
	while ((mb->iac & ADDRCHG) != 0);
	
	for (i = 0; i < 6; ++i)
		mb->padr = dev->dev_addr[i];

	/* clear the multicast filter */
	mb->iac = ADDRCHG | LOGADDR;

	while ((mb->iac & ADDRCHG) != 0);
	
	for (i = 0; i < 8; ++i)
		mb->ladrf = 0;

	mb->plscc = PORTSEL_GPSI + ENPLSIO;

	mb->maccc = ENXMT | ENRCV;
	mb->imr = RCVINT;
#endif

	mace_rxdma_reset(dev);
	mace_txdma_reset(dev);
	
	return 0;
}

/*
 * Shut down the mace and its interrupt channel
 */
 
static int mace_close(struct net_device *dev)
{
	struct mace_data *mp = (struct mace_data *) dev->priv;
	volatile struct mace *mb = mp->mace;

	mb->maccc = 0;		/* disable rx and tx	 */
	mb->imr = 0xFF;		/* disable all irqs	 */
	mace_dma_off(dev);	/* disable rx and tx dma */

	free_irq(dev->irq, dev);
	free_irq(IRQ_MAC_MACE_DMA, dev);

	free_pages((u32) mp->rx_ring, N_RX_PAGES);
	free_pages((u32) mp->tx_ring, 0);

	return 0;
}

/*
 * Transmit a frame
 */
 
static int mace_xmit_start(struct sk_buff *skb, struct net_device *dev)
{
	struct mace_data *mp = (struct mace_data *) dev->priv;

	/* Stop the queue if the buffer is full */

	if (!mp->tx_count) {
		netif_stop_queue(dev);
		return 1;
	}
	mp->tx_count--;
	
	mp->stats.tx_packets++;
	mp->stats.tx_bytes += skb->len;

	/* We need to copy into our xmit buffer to take care of alignment and caching issues */

	memcpy((void *) mp->tx_ring, skb->data, skb->len);

	/* load the Tx DMA and fire it off */

	psc_write_long(PSC_ENETWR_ADDR + mp->tx_slot, (u32)  mp->tx_ring_phys);
	psc_write_long(PSC_ENETWR_LEN + mp->tx_slot, skb->len);
	psc_write_word(PSC_ENETWR_CMD + mp->tx_slot, 0x9800);

	mp->tx_slot ^= 0x10;

	dev_kfree_skb(skb);

	return 0;
}

static struct net_device_stats *mace_stats(struct net_device *dev)
{
	struct mace_data *p = (struct mace_data *) dev->priv;
	return &p->stats;
}

static void mace_set_multicast(struct net_device *dev)
{
	struct mace_data *mp = (struct mace_data *) dev->priv;
	volatile struct mace *mb = mp->mace;
	int i, j;
	u32 crc;
	u8 maccc;

	maccc = mb->maccc;
	mb->maccc &= ~PROM;

	if (dev->flags & IFF_PROMISC) {
		mb->maccc |= PROM;
	} else {
		unsigned char multicast_filter[8];
		struct dev_mc_list *dmi = dev->mc_list;

		if (dev->flags & IFF_ALLMULTI) {
			for (i = 0; i < 8; i++) {
				multicast_filter[i] = 0xFF;
			}
		} else {
			for (i = 0; i < 8; i++)
				multicast_filter[i] = 0;
			for (i = 0; i < dev->mc_count; i++) {
				crc = ether_crc_le(6, dmi->dmi_addr);
				j = crc >> 26;	/* bit number in multicast_filter */
				multicast_filter[j >> 3] |= 1 << (j & 7);
				dmi = dmi->next;
			}
		}

		mb->iac = ADDRCHG | LOGADDR;
		while (mb->iac & ADDRCHG);
		
		for (i = 0; i < 8; ++i) {
			mb->ladrf = multicast_filter[i];
		}
	}

	mb->maccc = maccc;
}

/*
 * Miscellaneous interrupts are handled here. We may end up 
 * having to bash the chip on the head for bad errors
 */
 
static void mace_handle_misc_intrs(struct mace_data *mp, int intr)
{
	volatile struct mace *mb = mp->mace;
	static int mace_babbles, mace_jabbers;

	if (intr & MPCO) {
		mp->stats.rx_missed_errors += 256;
	}
	mp->stats.rx_missed_errors += mb->mpc;	/* reading clears it */

	if (intr & RNTPCO) {
		mp->stats.rx_length_errors += 256;
	}
	mp->stats.rx_length_errors += mb->rntpc;	/* reading clears it */

	if (intr & CERR) {
		++mp->stats.tx_heartbeat_errors;
	}
	if (intr & BABBLE) {
		if (mace_babbles++ < 4) {
			printk(KERN_DEBUG "mace: babbling transmitter\n");
		}
	}
	if (intr & JABBER) {
		if (mace_jabbers++ < 4) {
			printk(KERN_DEBUG "mace: jabbering transceiver\n");
		}
	}
}

/*
 *	A transmit error has occurred. (We kick the transmit side from
 *	the DMA completion)
 */
 
static void mace_xmit_error(struct net_device *dev)
{
	struct mace_data *mp = (struct mace_data *) dev->priv;
	volatile struct mace *mb = mp->mace;
	u8 xmtfs, xmtrc;
	
	xmtfs = mb->xmtfs;
	xmtrc = mb->xmtrc;
	
	if (xmtfs & XMTSV) {
		if (xmtfs & UFLO) {
			printk("%s: DMA underrun.\n", dev->name);
			mp->stats.tx_errors++;
			mp->stats.tx_fifo_errors++;
			mace_txdma_reset(dev);
		}
		if (xmtfs & RTRY) {
			mp->stats.collisions++;
		}
	}			
}

/*
 *	A receive interrupt occurred.
 */
 
static void mace_recv_interrupt(struct net_device *dev)
{
/*	struct mace_data *mp = (struct mace_data *) dev->priv; */
//	volatile struct mace *mb = mp->mace;
}

/*
 * Process the chip interrupt
 */
 
static irqreturn_t mace_interrupt(int irq, void *dev_id, struct pt_regs *regs)
{
	struct net_device *dev = (struct net_device *) dev_id;
	struct mace_data *mp = (struct mace_data *) dev->priv;
	volatile struct mace *mb = mp->mace;
	u8 ir;
	
	ir = mb->ir;
	mace_handle_misc_intrs(mp, ir);
	
	if (ir & XMTINT) {
		mace_xmit_error(dev);
	}
	if (ir & RCVINT) {
		mace_recv_interrupt(dev);
	}
	return IRQ_HANDLED;
}

static void mace_tx_timeout(struct net_device *dev)
{
/*	struct mace_data *mp = (struct mace_data *) dev->priv; */
//	volatile struct mace *mb = mp->mace;
}

/*
 * Handle a newly arrived frame
 */
 
static void mace_dma_rx_frame(struct net_device *dev, struct mace_frame *mf)
{
	struct mace_data *mp = (struct mace_data *) dev->priv;
	struct sk_buff *skb;

	if (mf->status & RS_OFLO) {
		printk("%s: fifo overflow.\n", dev->name);
		mp->stats.rx_errors++;
		mp->stats.rx_fifo_errors++;
	}
	if (mf->status&(RS_CLSN|RS_FRAMERR|RS_FCSERR))
		mp->stats.rx_errors++;
		
	if (mf->status&RS_CLSN) {
		mp->stats.collisions++;
	}
	if (mf->status&RS_FRAMERR) {
		mp->stats.rx_frame_errors++;
	}
	if (mf->status&RS_FCSERR) {
		mp->stats.rx_crc_errors++;
	}
		
	skb = dev_alloc_skb(mf->len+2);
	if (!skb) {
		mp->stats.rx_dropped++;
		return;
	}
	skb_reserve(skb,2);
	memcpy(skb_put(skb, mf->len), mf->data, mf->len);
	
	skb->dev = dev;
	skb->protocol = eth_type_trans(skb, dev);
	netif_rx(skb);
	dev->last_rx = jiffies;
	mp->stats.rx_packets++;
	mp->stats.rx_bytes += mf->len;
}

/*
 * The PSC has passed us a DMA interrupt event.
 */
 
static irqreturn_t mace_dma_intr(int irq, void *dev_id, struct pt_regs *regs)
{
	struct net_device *dev = (struct net_device *) dev_id;
	struct mace_data *mp = (struct mace_data *) dev->priv;
	int left, head;
	u16 status;
	u32 baka;

	/* Not sure what this does */

	while ((baka = psc_read_long(PSC_MYSTERY)) != psc_read_long(PSC_MYSTERY));
	if (!(baka & 0x60000000)) return IRQ_NONE;

	/*
	 * Process the read queue
	 */
		 
	status = psc_read_word(PSC_ENETRD_CTL);
		
	if (status & 0x2000) {
		mace_rxdma_reset(dev);
	} else if (status & 0x0100) {
		psc_write_word(PSC_ENETRD_CMD + mp->rx_slot, 0x1100);

		left = psc_read_long(PSC_ENETRD_LEN + mp->rx_slot);
		head = N_RX_RING - left;

		/* Loop through the ring buffer and process new packages */

		while (mp->rx_tail < head) {
			mace_dma_rx_frame(dev, (struct mace_frame *) (mp->rx_ring + (mp->rx_tail * 0x0800)));
			mp->rx_tail++;
		}
			
		/* If we're out of buffers in this ring then switch to */
		/* the other set, otherwise just reactivate this one.  */

		if (!left) {
			mace_load_rxdma_base(dev, mp->rx_slot);
			mp->rx_slot ^= 0x10;
		} else {
			psc_write_word(PSC_ENETRD_CMD + mp->rx_slot, 0x9800);
		}
	}
		
	/*
	 * Process the write queue
	 */

	status = psc_read_word(PSC_ENETWR_CTL);

	if (status & 0x2000) {
		mace_txdma_reset(dev);
	} else if (status & 0x0100) {
		psc_write_word(PSC_ENETWR_CMD + mp->tx_sloti, 0x0100);
		mp->tx_sloti ^= 0x10;
		mp->tx_count++;
		netif_wake_queue(dev);
	}
	return IRQ_HANDLED;
}

MODULE_LICENSE("GPL");
ass="hl opt">, { { /* xres, yres, xpos, ypos */ 0, 0, 0, 0, /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 | LCD_WINCTRL1_PO_16BPP, /* mode_winenable*/ LCD_WINENABLE_WEN0, }, { /* xres, yres, xpos, ypos */ 0, 0, 0, 0, /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 | LCD_WINCTRL1_PO_16BPP, /* mode_winenable*/ 0, }, { /* xres, yres, xpos, ypos */ 0, 0, 0, 0, /* mode_winctrl1 */ LCD_WINCTRL1_FRM_32BPP | LCD_WINCTRL1_PO_00|LCD_WINCTRL1_PIPE, /* mode_winenable*/ 0/*LCD_WINENABLE_WEN2*/, }, { /* xres, yres, xpos, ypos */ 0, 0, 0, 0, /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 | LCD_WINCTRL1_PO_16BPP | LCD_WINCTRL1_PIPE, /* mode_winenable*/ 0, }, }, }, /* Need VGA 640 @ 24bpp, @ 32bpp */ /* Need VGA 800 @ 24bpp, @ 32bpp */ /* Need VGA 1024 @ 24bpp, @ 32bpp */ }; /* * Controller configurations for various panels. */ struct panel_settings { const char name[25]; /* Full name <vendor>_<model> */ struct fb_monspecs monspecs; /* FB monitor specs */ /* panel timings */ uint32 mode_screen; uint32 mode_horztiming; uint32 mode_verttiming; uint32 mode_clkcontrol; uint32 mode_pwmdiv; uint32 mode_pwmhi; uint32 mode_outmask; uint32 mode_fifoctrl; uint32 mode_toyclksrc; uint32 mode_backlight; uint32 mode_auxpll; int (*device_init)(void); int (*device_shutdown)(void); #define Xres min_xres #define Yres min_yres u32 min_xres; /* Minimum horizontal resolution */ u32 max_xres; /* Maximum horizontal resolution */ u32 min_yres; /* Minimum vertical resolution */ u32 max_yres; /* Maximum vertical resolution */ }; /********************************************************************/ /* fixme: Maybe a modedb for the CRT ? otherwise panels should be as-is */ /* List of panels known to work with the AU1200 LCD controller. * To add a new panel, enter the same specifications as the * Generic_TFT one, and MAKE SURE that it doesn't conflicts * with the controller restrictions. Restrictions are: * * STN color panels: max_bpp <= 12 * STN mono panels: max_bpp <= 4 * TFT panels: max_bpp <= 16 * max_xres <= 800 * max_yres <= 600 */ static struct panel_settings known_lcd_panels[] = { [0] = { /* QVGA 320x240 H:33.3kHz V:110Hz */ .name = "QVGA_320x240", .monspecs = { .modedb = NULL, .modedb_len = 0, .hfmin = 30000, .hfmax = 70000, .vfmin = 60, .vfmax = 60, .dclkmin = 6000000, .dclkmax = 28000000, .input = FB_DISP_RGB, }, .mode_screen = LCD_SCREEN_SX_N(320) | LCD_SCREEN_SY_N(240), .mode_horztiming = 0x00c4623b, .mode_verttiming = 0x00502814, .mode_clkcontrol = 0x00020002, /* /4=24Mhz */ .mode_pwmdiv = 0x00000000, .mode_pwmhi = 0x00000000, .mode_outmask = 0x00FFFFFF, .mode_fifoctrl = 0x2f2f2f2f, .mode_toyclksrc = 0x00000004, /* AUXPLL directly */ .mode_backlight = 0x00000000, .mode_auxpll = 8, /* 96MHz AUXPLL */ .device_init = NULL, .device_shutdown = NULL, 320, 320, 240, 240, }, [1] = { /* VGA 640x480 H:30.3kHz V:58Hz */ .name = "VGA_640x480", .monspecs = { .modedb = NULL, .modedb_len = 0, .hfmin = 30000, .hfmax = 70000, .vfmin = 60, .vfmax = 60, .dclkmin = 6000000, .dclkmax = 28000000, .input = FB_DISP_RGB, }, .mode_screen = 0x13f9df80, .mode_horztiming = 0x003c5859, .mode_verttiming = 0x00741201, .mode_clkcontrol = 0x00020001, /* /4=24Mhz */ .mode_pwmdiv = 0x00000000, .mode_pwmhi = 0x00000000, .mode_outmask = 0x00FFFFFF, .mode_fifoctrl = 0x2f2f2f2f, .mode_toyclksrc = 0x00000004, /* AUXPLL directly */ .mode_backlight = 0x00000000, .mode_auxpll = 8, /* 96MHz AUXPLL */ .device_init = NULL, .device_shutdown = NULL, 640, 480, 640, 480, }, [2] = { /* SVGA 800x600 H:46.1kHz V:69Hz */ .name = "SVGA_800x600", .monspecs = { .modedb = NULL, .modedb_len = 0, .hfmin = 30000, .hfmax = 70000, .vfmin = 60, .vfmax = 60, .dclkmin = 6000000, .dclkmax = 28000000, .input = FB_DISP_RGB, }, .mode_screen = 0x18fa5780, .mode_horztiming = 0x00dc7e77, .mode_verttiming = 0x00584805, .mode_clkcontrol = 0x00020000, /* /2=48Mhz */ .mode_pwmdiv = 0x00000000, .mode_pwmhi = 0x00000000, .mode_outmask = 0x00FFFFFF, .mode_fifoctrl = 0x2f2f2f2f, .mode_toyclksrc = 0x00000004, /* AUXPLL directly */ .mode_backlight = 0x00000000, .mode_auxpll = 8, /* 96MHz AUXPLL */ .device_init = NULL, .device_shutdown = NULL, 800, 800, 600, 600, }, [3] = { /* XVGA 1024x768 H:56.2kHz V:70Hz */ .name = "XVGA_1024x768", .monspecs = { .modedb = NULL, .modedb_len = 0, .hfmin = 30000, .hfmax = 70000, .vfmin = 60, .vfmax = 60, .dclkmin = 6000000, .dclkmax = 28000000, .input = FB_DISP_RGB, }, .mode_screen = 0x1ffaff80, .mode_horztiming = 0x007d0e57, .mode_verttiming = 0x00740a01, .mode_clkcontrol = 0x000A0000, /* /1 */ .mode_pwmdiv = 0x00000000, .mode_pwmhi = 0x00000000, .mode_outmask = 0x00FFFFFF, .mode_fifoctrl = 0x2f2f2f2f, .mode_toyclksrc = 0x00000004, /* AUXPLL directly */ .mode_backlight = 0x00000000, .mode_auxpll = 6, /* 72MHz AUXPLL */ .device_init = NULL, .device_shutdown = NULL, 1024, 1024, 768, 768, }, [4] = { /* XVGA XVGA 1280x1024 H:68.5kHz V:65Hz */ .name = "XVGA_1280x1024", .monspecs = { .modedb = NULL, .modedb_len = 0, .hfmin = 30000, .hfmax = 70000, .vfmin = 60, .vfmax = 60, .dclkmin = 6000000, .dclkmax = 28000000, .input = FB_DISP_RGB, }, .mode_screen = 0x27fbff80, .mode_horztiming = 0x00cdb2c7, .mode_verttiming = 0x00600002, .mode_clkcontrol = 0x000A0000, /* /1 */ .mode_pwmdiv = 0x00000000, .mode_pwmhi = 0x00000000, .mode_outmask = 0x00FFFFFF, .mode_fifoctrl = 0x2f2f2f2f, .mode_toyclksrc = 0x00000004, /* AUXPLL directly */ .mode_backlight = 0x00000000, .mode_auxpll = 10, /* 120MHz AUXPLL */ .device_init = NULL, .device_shutdown = NULL, 1280, 1280, 1024, 1024, }, [5] = { /* Samsung 1024x768 TFT */ .name = "Samsung_1024x768_TFT", .monspecs = { .modedb = NULL, .modedb_len = 0, .hfmin = 30000, .hfmax = 70000, .vfmin = 60, .vfmax = 60, .dclkmin = 6000000, .dclkmax = 28000000, .input = FB_DISP_RGB, }, .mode_screen = 0x1ffaff80, .mode_horztiming = 0x018cc677, .mode_verttiming = 0x00241217, .mode_clkcontrol = 0x00000000, /* SCB 0x1 /4=24Mhz */ .mode_pwmdiv = 0x8000063f, /* SCB 0x0 */ .mode_pwmhi = 0x03400000, /* SCB 0x0 */ .mode_outmask = 0x00FFFFFF, .mode_fifoctrl = 0x2f2f2f2f, .mode_toyclksrc = 0x00000004, /* AUXPLL directly */ .mode_backlight = 0x00000000, .mode_auxpll = 8, /* 96MHz AUXPLL */ .device_init = board_au1200fb_panel_init, .device_shutdown = board_au1200fb_panel_shutdown, 1024, 1024, 768, 768, }, [6] = { /* Toshiba 640x480 TFT */ .name = "Toshiba_640x480_TFT", .monspecs = { .modedb = NULL, .modedb_len = 0, .hfmin = 30000, .hfmax = 70000, .vfmin = 60, .vfmax = 60, .dclkmin = 6000000, .dclkmax = 28000000, .input = FB_DISP_RGB, }, .mode_screen = LCD_SCREEN_SX_N(640) | LCD_SCREEN_SY_N(480), .mode_horztiming = LCD_HORZTIMING_HPW_N(96) | LCD_HORZTIMING_HND1_N(13) | LCD_HORZTIMING_HND2_N(51), .mode_verttiming = LCD_VERTTIMING_VPW_N(2) | LCD_VERTTIMING_VND1_N(11) | LCD_VERTTIMING_VND2_N(32), .mode_clkcontrol = 0x00000000, /* /4=24Mhz */ .mode_pwmdiv = 0x8000063f, .mode_pwmhi = 0x03400000, .mode_outmask = 0x00fcfcfc, .mode_fifoctrl = 0x2f2f2f2f, .mode_toyclksrc = 0x00000004, /* AUXPLL directly */ .mode_backlight = 0x00000000, .mode_auxpll = 8, /* 96MHz AUXPLL */ .device_init = board_au1200fb_panel_init, .device_shutdown = board_au1200fb_panel_shutdown, 640, 480, 640, 480, }, [7] = { /* Sharp 320x240 TFT */ .name = "Sharp_320x240_TFT", .monspecs = { .modedb = NULL, .modedb_len = 0, .hfmin = 12500, .hfmax = 20000, .vfmin = 38, .vfmax = 81, .dclkmin = 4500000, .dclkmax = 6800000, .input = FB_DISP_RGB, }, .mode_screen = LCD_SCREEN_SX_N(320) | LCD_SCREEN_SY_N(240), .mode_horztiming = LCD_HORZTIMING_HPW_N(60) | LCD_HORZTIMING_HND1_N(13) | LCD_HORZTIMING_HND2_N(2), .mode_verttiming = LCD_VERTTIMING_VPW_N(2) | LCD_VERTTIMING_VND1_N(2) | LCD_VERTTIMING_VND2_N(5), .mode_clkcontrol = LCD_CLKCONTROL_PCD_N(7), /*16=6Mhz*/ .mode_pwmdiv = 0x8000063f, .mode_pwmhi = 0x03400000, .mode_outmask = 0x00fcfcfc, .mode_fifoctrl = 0x2f2f2f2f, .mode_toyclksrc = 0x00000004, /* AUXPLL directly */ .mode_backlight = 0x00000000, .mode_auxpll = 8, /* 96MHz AUXPLL */ .device_init = board_au1200fb_panel_init, .device_shutdown = board_au1200fb_panel_shutdown, 320, 320, 240, 240, }, [8] = { /* Toppoly TD070WGCB2 7" 856x480 TFT */ .name = "Toppoly_TD070WGCB2", .monspecs = { .modedb = NULL, .modedb_len = 0, .hfmin = 30000, .hfmax = 70000, .vfmin = 60, .vfmax = 60, .dclkmin = 6000000, .dclkmax = 28000000, .input = FB_DISP_RGB, }, .mode_screen = LCD_SCREEN_SX_N(856) | LCD_SCREEN_SY_N(480), .mode_horztiming = LCD_HORZTIMING_HND2_N(43) | LCD_HORZTIMING_HND1_N(43) | LCD_HORZTIMING_HPW_N(114), .mode_verttiming = LCD_VERTTIMING_VND2_N(20) | LCD_VERTTIMING_VND1_N(21) | LCD_VERTTIMING_VPW_N(4), .mode_clkcontrol = 0x00020001, /* /4=24Mhz */ .mode_pwmdiv = 0x8000063f, .mode_pwmhi = 0x03400000, .mode_outmask = 0x00fcfcfc, .mode_fifoctrl = 0x2f2f2f2f, .mode_toyclksrc = 0x00000004, /* AUXPLL directly */ .mode_backlight = 0x00000000, .mode_auxpll = 8, /* 96MHz AUXPLL */ .device_init = board_au1200fb_panel_init, .device_shutdown = board_au1200fb_panel_shutdown, 856, 856, 480, 480, }, }; #define NUM_PANELS (ARRAY_SIZE(known_lcd_panels)) /********************************************************************/ #ifdef CONFIG_PM static int set_brightness(unsigned int brightness) { unsigned int hi1, divider; /* limit brightness pwm duty to >= 30/1600 */ if (brightness < 30) { brightness = 30; } divider = (lcd->pwmdiv & 0x3FFFF) + 1; hi1 = (lcd->pwmhi >> 16) + 1; hi1 = (((brightness & 0xFF) + 1) * divider >> 8); lcd->pwmhi &= 0xFFFF; lcd->pwmhi |= (hi1 << 16); return brightness; } #endif /* CONFIG_PM */ static int winbpp (unsigned int winctrl1) { int bits = 0; /* how many bits are needed for each pixel format */ switch (winctrl1 & LCD_WINCTRL1_FRM) { case LCD_WINCTRL1_FRM_1BPP: bits = 1; break; case LCD_WINCTRL1_FRM_2BPP: bits = 2; break; case LCD_WINCTRL1_FRM_4BPP: bits = 4; break; case LCD_WINCTRL1_FRM_8BPP: bits = 8; break; case LCD_WINCTRL1_FRM_12BPP: case LCD_WINCTRL1_FRM_16BPP655: case LCD_WINCTRL1_FRM_16BPP565: case LCD_WINCTRL1_FRM_16BPP556: case LCD_WINCTRL1_FRM_16BPPI1555: case LCD_WINCTRL1_FRM_16BPPI5551: case LCD_WINCTRL1_FRM_16BPPA1555: case LCD_WINCTRL1_FRM_16BPPA5551: bits = 16; break; case LCD_WINCTRL1_FRM_24BPP: case LCD_WINCTRL1_FRM_32BPP: bits = 32; break; } return bits; } static int fbinfo2index (struct fb_info *fb_info) { int i; for (i = 0; i < CONFIG_FB_AU1200_DEVS; ++i) { if (fb_info == (struct fb_info *)(&_au1200fb_devices[i].fb_info)) return i; } printk("au1200fb: ERROR: fbinfo2index failed!\n"); return -1; } static int au1200_setlocation (struct au1200fb_device *fbdev, int plane, int xpos, int ypos) { uint32 winctrl0, winctrl1, winenable, fb_offset = 0; int xsz, ysz; /* FIX!!! NOT CHECKING FOR COMPLETE OFFSCREEN YET */ winctrl0 = lcd->window[plane].winctrl0; winctrl1 = lcd->window[plane].winctrl1; winctrl0 &= (LCD_WINCTRL0_A | LCD_WINCTRL0_AEN); winctrl1 &= ~(LCD_WINCTRL1_SZX | LCD_WINCTRL1_SZY); /* Check for off-screen adjustments */ xsz = win->w[plane].xres; ysz = win->w[plane].yres; if ((xpos + win->w[plane].xres) > panel->Xres) { /* Off-screen to the right */ xsz = panel->Xres - xpos; /* off by 1 ??? */ /*printk("off screen right\n");*/ } if ((ypos + win->w[plane].yres) > panel->Yres) { /* Off-screen to the bottom */ ysz = panel->Yres - ypos; /* off by 1 ??? */ /*printk("off screen bottom\n");*/ } if (xpos < 0) { /* Off-screen to the left */ xsz = win->w[plane].xres + xpos; fb_offset += (((0 - xpos) * winbpp(lcd->window[plane].winctrl1))/8); xpos = 0; /*printk("off screen left\n");*/ } if (ypos < 0) { /* Off-screen to the top */ ysz = win->w[plane].yres + ypos; /* fixme: fb_offset += ((0-ypos)*fb_pars[plane].line_length); */ ypos = 0; /*printk("off screen top\n");*/ } /* record settings */ win->w[plane].xpos = xpos; win->w[plane].ypos = ypos; xsz -= 1; ysz -= 1; winctrl0 |= (xpos << 21); winctrl0 |= (ypos << 10); winctrl1 |= (xsz << 11); winctrl1 |= (ysz << 0); /* Disable the window while making changes, then restore WINEN */ winenable = lcd->winenable & (1 << plane); au_sync(); lcd->winenable &= ~(1 << plane); lcd->window[plane].winctrl0 = winctrl0; lcd->window[plane].winctrl1 = winctrl1; lcd->window[plane].winbuf0 = lcd->window[plane].winbuf1 = fbdev->fb_phys; lcd->window[plane].winbufctrl = 0; /* select winbuf0 */ lcd->winenable |= winenable; au_sync(); return 0; } static void au1200_setpanel (struct panel_settings *newpanel) { /* * Perform global setup/init of LCD controller */ uint32 winenable; /* Make sure all windows disabled */ winenable = lcd->winenable; lcd->winenable = 0; au_sync(); /* * Ensure everything is disabled before reconfiguring */ if (lcd->screen & LCD_SCREEN_SEN) { /* Wait for vertical sync period */ lcd->intstatus = LCD_INT_SS; while ((lcd->intstatus & LCD_INT_SS) == 0) { au_sync(); } lcd->screen &= ~LCD_SCREEN_SEN; /*disable the controller*/ do { lcd->intstatus = lcd->intstatus; /*clear interrupts*/ au_sync(); /*wait for controller to shut down*/ } while ((lcd->intstatus & LCD_INT_SD) == 0); /* Call shutdown of current panel (if up) */ /* this must occur last, because if an external clock is driving the controller, the clock cannot be turned off before first shutting down the controller. */ if (panel->device_shutdown != NULL) panel->device_shutdown(); } /* Newpanel == NULL indicates a shutdown operation only */ if (newpanel == NULL) return; panel = newpanel; printk("Panel(%s), %dx%d\n", panel->name, panel->Xres, panel->Yres); /* * Setup clocking if internal LCD clock source (assumes sys_auxpll valid) */ if (!(panel->mode_clkcontrol & LCD_CLKCONTROL_EXT)) { uint32 sys_clksrc; au_writel(panel->mode_auxpll, SYS_AUXPLL); sys_clksrc = au_readl(SYS_CLKSRC) & ~0x0000001f; sys_clksrc |= panel->mode_toyclksrc; au_writel(sys_clksrc, SYS_CLKSRC); } /* * Configure panel timings */ lcd->screen = panel->mode_screen; lcd->horztiming = panel->mode_horztiming; lcd->verttiming = panel->mode_verttiming; lcd->clkcontrol = panel->mode_clkcontrol; lcd->pwmdiv = panel->mode_pwmdiv; lcd->pwmhi = panel->mode_pwmhi; lcd->outmask = panel->mode_outmask; lcd->fifoctrl = panel->mode_fifoctrl; au_sync(); /* fixme: Check window settings to make sure still valid * for new geometry */ #if 0 au1200_setlocation(fbdev, 0, win->w[0].xpos, win->w[0].ypos); au1200_setlocation(fbdev, 1, win->w[1].xpos, win->w[1].ypos); au1200_setlocation(fbdev, 2, win->w[2].xpos, win->w[2].ypos); au1200_setlocation(fbdev, 3, win->w[3].xpos, win->w[3].ypos); #endif lcd->winenable = winenable; /* * Re-enable screen now that it is configured */ lcd->screen |= LCD_SCREEN_SEN; au_sync(); /* Call init of panel */ if (panel->device_init != NULL) panel->device_init(); /* FIX!!!! not appropriate on panel change!!! Global setup/init */ lcd->intenable = 0; lcd->intstatus = ~0; lcd->backcolor = win->mode_backcolor; /* Setup Color Key - FIX!!! */ lcd->colorkey = win->mode_colorkey; lcd->colorkeymsk = win->mode_colorkeymsk; /* Setup HWCursor - FIX!!! Need to support this eventually */ lcd->hwc.cursorctrl = 0; lcd->hwc.cursorpos = 0; lcd->hwc.cursorcolor0 = 0; lcd->hwc.cursorcolor1 = 0; lcd->hwc.cursorcolor2 = 0; lcd->hwc.cursorcolor3 = 0; #if 0 #define D(X) printk("%25s: %08X\n", #X, X) D(lcd->screen); D(lcd->horztiming); D(lcd->verttiming); D(lcd->clkcontrol); D(lcd->pwmdiv); D(lcd->pwmhi); D(lcd->outmask); D(lcd->fifoctrl); D(lcd->window[0].winctrl0); D(lcd->window[0].winctrl1); D(lcd->window[0].winctrl2); D(lcd->window[0].winbuf0); D(lcd->window[0].winbuf1); D(lcd->window[0].winbufctrl); D(lcd->window[1].winctrl0); D(lcd->window[1].winctrl1); D(lcd->window[1].winctrl2); D(lcd->window[1].winbuf0); D(lcd->window[1].winbuf1); D(lcd->window[1].winbufctrl); D(lcd->window[2].winctrl0); D(lcd->window[2].winctrl1); D(lcd->window[2].winctrl2); D(lcd->window[2].winbuf0); D(lcd->window[2].winbuf1); D(lcd->window[2].winbufctrl); D(lcd->window[3].winctrl0); D(lcd->window[3].winctrl1); D(lcd->window[3].winctrl2); D(lcd->window[3].winbuf0); D(lcd->window[3].winbuf1); D(lcd->window[3].winbufctrl); D(lcd->winenable); D(lcd->intenable); D(lcd->intstatus); D(lcd->backcolor); D(lcd->winenable); D(lcd->colorkey); D(lcd->colorkeymsk); D(lcd->hwc.cursorctrl); D(lcd->hwc.cursorpos); D(lcd->hwc.cursorcolor0); D(lcd->hwc.cursorcolor1); D(lcd->hwc.cursorcolor2); D(lcd->hwc.cursorcolor3); #endif } static void au1200_setmode(struct au1200fb_device *fbdev) { int plane = fbdev->plane; /* Window/plane setup */ lcd->window[plane].winctrl1 = ( 0 | LCD_WINCTRL1_PRI_N(plane) | win->w[plane].mode_winctrl1 /* FRM,CCO,PO,PIPE */ ) ; au1200_setlocation(fbdev, plane, win->w[plane].xpos, win->w[plane].ypos); lcd->window[plane].winctrl2 = ( 0 | LCD_WINCTRL2_CKMODE_00 | LCD_WINCTRL2_DBM | LCD_WINCTRL2_BX_N( fbdev->fb_info.fix.line_length) | LCD_WINCTRL2_SCX_1 | LCD_WINCTRL2_SCY_1 ) ; lcd->winenable |= win->w[plane].mode_winenable; au_sync(); } /* Inline helpers */ /*#define panel_is_dual(panel) ((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/ /*#define panel_is_active(panel)((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/ #define panel_is_color(panel) ((panel->mode_screen & LCD_SCREEN_PT) <= LCD_SCREEN_PT_CDSTN) /* Bitfields format supported by the controller. */ static struct fb_bitfield rgb_bitfields[][4] = { /* Red, Green, Blue, Transp */ [LCD_WINCTRL1_FRM_16BPP655 >> 25] = { { 10, 6, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } }, [LCD_WINCTRL1_FRM_16BPP565 >> 25] = { { 11, 5, 0 }, { 5, 6, 0 }, { 0, 5, 0 }, { 0, 0, 0 } }, [LCD_WINCTRL1_FRM_16BPP556 >> 25] = { { 11, 5, 0 }, { 6, 5, 0 }, { 0, 6, 0 }, { 0, 0, 0 } }, [LCD_WINCTRL1_FRM_16BPPI1555 >> 25] = { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } }, [LCD_WINCTRL1_FRM_16BPPI5551 >> 25] = { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 0, 0 } }, [LCD_WINCTRL1_FRM_16BPPA1555 >> 25] = { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 15, 1, 0 } }, [LCD_WINCTRL1_FRM_16BPPA5551 >> 25] = { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 1, 0 } }, [LCD_WINCTRL1_FRM_24BPP >> 25] = { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 0, 0, 0 } }, [LCD_WINCTRL1_FRM_32BPP >> 25] = { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 24, 0, 0 } }, }; /*-------------------------------------------------------------------------*/ /* Helpers */ static void au1200fb_update_fbinfo(struct fb_info *fbi) { /* FIX!!!! This also needs to take the window pixel format into account!!! */ /* Update var-dependent FB info */ if (panel_is_color(panel)) { if (fbi->var.bits_per_pixel <= 8) { /* palettized */ fbi->fix.visual = FB_VISUAL_PSEUDOCOLOR; fbi->fix.line_length = fbi->var.xres_virtual / (8/fbi->var.bits_per_pixel); } else { /* non-palettized */ fbi->fix.visual = FB_VISUAL_TRUECOLOR; fbi->fix.line_length = fbi->var.xres_virtual * (fbi->var.bits_per_pixel / 8); } } else { /* mono FIX!!! mono 8 and 4 bits */ fbi->fix.visual = FB_VISUAL_MONO10; fbi->fix.line_length = fbi->var.xres_virtual / 8; } fbi->screen_size = fbi->fix.line_length * fbi->var.yres_virtual; print_dbg("line length: %d\n", fbi->fix.line_length); print_dbg("bits_per_pixel: %d\n", fbi->var.bits_per_pixel); } /*-------------------------------------------------------------------------*/ /* AU1200 framebuffer driver */ /* fb_check_var * Validate var settings with hardware restrictions and modify it if necessary */ static int au1200fb_fb_check_var(struct fb_var_screeninfo *var, struct fb_info *fbi) { struct au1200fb_device *fbdev = (struct au1200fb_device *)fbi; u32 pixclock; int screen_size, plane; plane = fbdev->plane; /* Make sure that the mode respect all LCD controller and * panel restrictions. */ var->xres = win->w[plane].xres; var->yres = win->w[plane].yres; /* No need for virtual resolution support */ var->xres_virtual = var->xres; var->yres_virtual = var->yres; var->bits_per_pixel = winbpp(win->w[plane].mode_winctrl1); screen_size = var->xres_virtual * var->yres_virtual; if (var->bits_per_pixel > 8) screen_size *= (var->bits_per_pixel / 8); else screen_size /= (8/var->bits_per_pixel); if (fbdev->fb_len < screen_size) return -EINVAL; /* Virtual screen is to big, abort */ /* FIX!!!! what are the implicaitons of ignoring this for windows ??? */ /* The max LCD clock is fixed to 48MHz (value of AUX_CLK). The pixel * clock can only be obtain by dividing this value by an even integer. * Fallback to a slower pixel clock if necessary. */ pixclock = max((u32)(PICOS2KHZ(var->pixclock) * 1000), fbi->monspecs.dclkmin); pixclock = min(pixclock, min(fbi->monspecs.dclkmax, (u32)AU1200_LCD_MAX_CLK/2)); if (AU1200_LCD_MAX_CLK % pixclock) { int diff = AU1200_LCD_MAX_CLK % pixclock; pixclock -= diff; } var->pixclock = KHZ2PICOS(pixclock/1000); #if 0 if (!panel_is_active(panel)) { int pcd = AU1200_LCD_MAX_CLK / (pixclock * 2) - 1; if (!panel_is_color(panel) && (panel->control_base & LCD_CONTROL_MPI) && (pcd < 3)) { /* STN 8bit mono panel support is up to 6MHz pixclock */ var->pixclock = KHZ2PICOS(6000); } else if (!pcd) { /* Other STN panel support is up to 12MHz */ var->pixclock = KHZ2PICOS(12000); } } #endif /* Set bitfield accordingly */ switch (var->bits_per_pixel) { case 16: { /* 16bpp True color. * These must be set to MATCH WINCTRL[FORM] */ int idx; idx = (win->w[0].mode_winctrl1 & LCD_WINCTRL1_FRM) >> 25; var->red = rgb_bitfields[idx][0]; var->green = rgb_bitfields[idx][1]; var->blue = rgb_bitfields[idx][2]; var->transp = rgb_bitfields[idx][3]; break; } case 32: { /* 32bpp True color. * These must be set to MATCH WINCTRL[FORM] */ int idx; idx = (win->w[0].mode_winctrl1 & LCD_WINCTRL1_FRM) >> 25; var->red = rgb_bitfields[idx][0]; var->green = rgb_bitfields[idx][1]; var->blue = rgb_bitfields[idx][2]; var->transp = rgb_bitfields[idx][3]; break; } default: print_dbg("Unsupported depth %dbpp", var->bits_per_pixel); return -EINVAL; } return 0; } /* fb_set_par * Set hardware with var settings. This will enable the controller with a * specific mode, normally validated with the fb_check_var method */ static int au1200fb_fb_set_par(struct fb_info *fbi) { struct au1200fb_device *fbdev = (struct au1200fb_device *)fbi; au1200fb_update_fbinfo(fbi); au1200_setmode(fbdev); return 0; } /* fb_setcolreg * Set color in LCD palette. */ static int au1200fb_fb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *fbi) { volatile u32 *palette = lcd->palette; u32 value; if (regno > (AU1200_LCD_NBR_PALETTE_ENTRIES - 1)) return -EINVAL; if (fbi->var.grayscale) { /* Convert color to grayscale */ red = green = blue = (19595 * red + 38470 * green + 7471 * blue) >> 16; } if (fbi->fix.visual == FB_VISUAL_TRUECOLOR) { /* Place color in the pseudopalette */ if (regno > 16) return -EINVAL; palette = (u32*) fbi->pseudo_palette; red >>= (16 - fbi->var.red.length); green >>= (16 - fbi->var.green.length); blue >>= (16 - fbi->var.blue.length); value = (red << fbi->var.red.offset) | (green << fbi->var.green.offset)| (blue << fbi->var.blue.offset); value &= 0xFFFF; } else if (1 /*FIX!!! panel_is_active(fbdev->panel)*/) { /* COLOR TFT PALLETTIZED (use RGB 565) */ value = (red & 0xF800)|((green >> 5) & 0x07E0)|((blue >> 11) & 0x001F); value &= 0xFFFF; } else if (0 /*panel_is_color(fbdev->panel)*/) { /* COLOR STN MODE */ value = 0x1234; value &= 0xFFF; } else { /* MONOCHROME MODE */ value = (green >> 12) & 0x000F; value &= 0xF; } palette[regno] = value; return 0; } /* fb_blank * Blank the screen. Depending on the mode, the screen will be * activated with the backlight color, or desactivated */ static int au1200fb_fb_blank(int blank_mode, struct fb_info *fbi) { /* Short-circuit screen blanking */ if (noblanking) return 0; switch (blank_mode) { case FB_BLANK_UNBLANK: case FB_BLANK_NORMAL: /* printk("turn on panel\n"); */ au1200_setpanel(panel); break; case FB_BLANK_VSYNC_SUSPEND: case FB_BLANK_HSYNC_SUSPEND: case FB_BLANK_POWERDOWN: /* printk("turn off panel\n"); */ au1200_setpanel(NULL); break; default: break; } /* FB_BLANK_NORMAL is a soft blank */ return (blank_mode == FB_BLANK_NORMAL) ? -EINVAL : 0; } /* fb_mmap * Map video memory in user space. We don't use the generic fb_mmap * method mainly to allow the use of the TLB streaming flag (CCA=6) */ static int au1200fb_fb_mmap(struct fb_info *info, struct vm_area_struct *vma) { unsigned int len; unsigned long start=0, off; struct au1200fb_device *fbdev = (struct au1200fb_device *) info; #ifdef CONFIG_PM au1xxx_pm_access(LCD_pm_dev); #endif if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) { return -EINVAL; } start = fbdev->fb_phys & PAGE_MASK; len = PAGE_ALIGN((start & ~PAGE_MASK) + fbdev->fb_len); off = vma->vm_pgoff << PAGE_SHIFT; if ((vma->vm_end - vma->vm_start + off) > len) { return -EINVAL; } off += start; vma->vm_pgoff = off >> PAGE_SHIFT; vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); pgprot_val(vma->vm_page_prot) |= _CACHE_MASK; /* CCA=7 */ vma->vm_flags |= VM_IO; return io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT, vma->vm_end - vma->vm_start, vma->vm_page_prot); return 0; } static void set_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata) { unsigned int hi1, divider; /* SCREEN_SIZE: user cannot reset size, must switch panel choice */ if (pdata->flags & SCREEN_BACKCOLOR) lcd->backcolor = pdata->backcolor; if (pdata->flags & SCREEN_BRIGHTNESS) { // limit brightness pwm duty to >= 30/1600 if (pdata->brightness < 30) { pdata->brightness = 30; } divider = (lcd->pwmdiv & 0x3FFFF) + 1; hi1 = (lcd->pwmhi >> 16) + 1; hi1 = (((pdata->brightness & 0xFF)+1) * divider >> 8); lcd->pwmhi &= 0xFFFF; lcd->pwmhi |= (hi1 << 16); } if (pdata->flags & SCREEN_COLORKEY) lcd->colorkey = pdata->colorkey; if (pdata->flags & SCREEN_MASK) lcd->colorkeymsk = pdata->mask; au_sync(); } static void get_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata) { unsigned int hi1, divider; pdata->xsize = ((lcd->screen & LCD_SCREEN_SX) >> 19) + 1; pdata->ysize = ((lcd->screen & LCD_SCREEN_SY) >> 8) + 1; pdata->backcolor = lcd->backcolor; pdata->colorkey = lcd->colorkey; pdata->mask = lcd->colorkeymsk; // brightness hi1 = (lcd->pwmhi >> 16) + 1; divider = (lcd->pwmdiv & 0x3FFFF) + 1; pdata->brightness = ((hi1 << 8) / divider) - 1; au_sync(); } static void set_window(unsigned int plane, struct au1200_lcd_window_regs_t *pdata) { unsigned int val, bpp; /* Window control register 0 */ if (pdata->flags & WIN_POSITION) { val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_OX | LCD_WINCTRL0_OY); val |= ((pdata->xpos << 21) & LCD_WINCTRL0_OX); val |= ((pdata->ypos << 10) & LCD_WINCTRL0_OY); lcd->window[plane].winctrl0 = val; } if (pdata->flags & WIN_ALPHA_COLOR) { val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_A); val |= ((pdata->alpha_color << 2) & LCD_WINCTRL0_A); lcd->window[plane].winctrl0 = val; } if (pdata->flags & WIN_ALPHA_MODE) { val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_AEN); val |= ((pdata->alpha_mode << 1) & LCD_WINCTRL0_AEN); lcd->window[plane].winctrl0 = val; } /* Window control register 1 */ if (pdata->flags & WIN_PRIORITY) { val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PRI); val |= ((pdata->priority << 30) & LCD_WINCTRL1_PRI); lcd->window[plane].winctrl1 = val; } if (pdata->flags & WIN_CHANNEL) { val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PIPE); val |= ((pdata->channel << 29) & LCD_WINCTRL1_PIPE); lcd->window[plane].winctrl1 = val; } if (pdata->flags & WIN_BUFFER_FORMAT) { val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_FRM); val |= ((pdata->buffer_format << 25) & LCD_WINCTRL1_FRM); lcd->window[plane].winctrl1 = val; } if (pdata->flags & WIN_COLOR_ORDER) { val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_CCO); val |= ((pdata->color_order << 24) & LCD_WINCTRL1_CCO); lcd->window[plane].winctrl1 = val; } if (pdata->flags & WIN_PIXEL_ORDER) { val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PO); val |= ((pdata->pixel_order << 22) & LCD_WINCTRL1_PO); lcd->window[plane].winctrl1 = val; } if (pdata->flags & WIN_SIZE) { val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_SZX | LCD_WINCTRL1_SZY); val |= (((pdata->xsize << 11) - 1) & LCD_WINCTRL1_SZX); val |= (((pdata->ysize) - 1) & LCD_WINCTRL1_SZY); lcd->window[plane].winctrl1 = val; /* program buffer line width */ bpp = winbpp(val) / 8; val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_BX); val |= (((pdata->xsize * bpp) << 8) & LCD_WINCTRL2_BX); lcd->window[plane].winctrl2 = val; } /* Window control register 2 */ if (pdata->flags & WIN_COLORKEY_MODE) { val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_CKMODE); val |= ((pdata->colorkey_mode << 24) & LCD_WINCTRL2_CKMODE); lcd->window[plane].winctrl2 = val; } if (pdata->flags & WIN_DOUBLE_BUFFER_MODE) { val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_DBM); val |= ((pdata->double_buffer_mode << 23) & LCD_WINCTRL2_DBM); lcd->window[plane].winctrl2 = val; } if (pdata->flags & WIN_RAM_ARRAY_MODE) { val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_RAM); val |= ((pdata->ram_array_mode << 21) & LCD_WINCTRL2_RAM); lcd->window[plane].winctrl2 = val; } /* Buffer line width programmed with WIN_SIZE */ if (pdata->flags & WIN_BUFFER_SCALE) { val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_SCX | LCD_WINCTRL2_SCY); val |= ((pdata->xsize << 11) & LCD_WINCTRL2_SCX); val |= ((pdata->ysize) & LCD_WINCTRL2_SCY); lcd->window[plane].winctrl2 = val; } if (pdata->flags & WIN_ENABLE) { val = lcd->winenable; val &= ~(1<<plane); val |= (pdata->enable & 1) << plane; lcd->winenable = val; } au_sync(); } static void get_window(unsigned int plane, struct au1200_lcd_window_regs_t *pdata) { /* Window control register 0 */ pdata->xpos = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_OX) >> 21; pdata->ypos = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_OY) >> 10; pdata->alpha_color = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_A) >> 2; pdata->alpha_mode = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_AEN) >> 1; /* Window control register 1 */ pdata->priority = (lcd->window[plane].winctrl1& LCD_WINCTRL1_PRI) >> 30; pdata->channel = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_PIPE) >> 29; pdata->buffer_format = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_FRM) >> 25; pdata->color_order = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_CCO) >> 24; pdata->pixel_order = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_PO) >> 22; pdata->xsize = ((lcd->window[plane].winctrl1 & LCD_WINCTRL1_SZX) >> 11) + 1; pdata->ysize = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_SZY) + 1; /* Window control register 2 */ pdata->colorkey_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_CKMODE) >> 24; pdata->double_buffer_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_DBM) >> 23; pdata->ram_array_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_RAM) >> 21; pdata->enable = (lcd->winenable >> plane) & 1; au_sync(); } static int au1200fb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg) { int plane; int val; #ifdef CONFIG_PM au1xxx_pm_access(LCD_pm_dev); #endif plane = fbinfo2index(info); print_dbg("au1200fb: ioctl %d on plane %d\n", cmd, plane); if (cmd == AU1200_LCD_FB_IOCTL) { struct au1200_lcd_iodata_t iodata; if (copy_from_user(&iodata, (void __user *) arg, sizeof(iodata))) return -EFAULT; print_dbg("FB IOCTL called\n"); switch (iodata.subcmd) { case AU1200_LCD_SET_SCREEN: print_dbg("AU1200_LCD_SET_SCREEN\n"); set_global(cmd, &iodata.global); break; case AU1200_LCD_GET_SCREEN: print_dbg("AU1200_LCD_GET_SCREEN\n"); get_global(cmd, &iodata.global); break; case AU1200_LCD_SET_WINDOW: print_dbg("AU1200_LCD_SET_WINDOW\n"); set_window(plane, &iodata.window); break; case AU1200_LCD_GET_WINDOW: print_dbg("AU1200_LCD_GET_WINDOW\n"); get_window(plane, &iodata.window); break; case AU1200_LCD_SET_PANEL: print_dbg("AU1200_LCD_SET_PANEL\n"); if ((iodata.global.panel_choice >= 0) && (iodata.global.panel_choice < NUM_PANELS)) { struct panel_settings *newpanel; panel_index = iodata.global.panel_choice; newpanel = &known_lcd_panels[panel_index]; au1200_setpanel(newpanel); } break; case AU1200_LCD_GET_PANEL: print_dbg("AU1200_LCD_GET_PANEL\n"); iodata.global.panel_choice = panel_index; break; default: return -EINVAL; } val = copy_to_user((void __user *) arg, &iodata, sizeof(iodata)); if (val) { print_dbg("error: could not copy %d bytes\n", val); return -EFAULT; } } return 0; } static struct fb_ops au1200fb_fb_ops = { .owner = THIS_MODULE, .fb_check_var = au1200fb_fb_check_var, .fb_set_par = au1200fb_fb_set_par, .fb_setcolreg = au1200fb_fb_setcolreg, .fb_blank = au1200fb_fb_blank, .fb_fillrect = cfb_fillrect, .fb_copyarea = cfb_copyarea, .fb_imageblit = cfb_imageblit, .fb_sync = NULL, .fb_ioctl = au1200fb_ioctl, .fb_mmap = au1200fb_fb_mmap, }; /*-------------------------------------------------------------------------*/ static irqreturn_t au1200fb_handle_irq(int irq, void* dev_id) { /* Nothing to do for now, just clear any pending interrupt */ lcd->intstatus = lcd->intstatus; au_sync(); return IRQ_HANDLED; } /*-------------------------------------------------------------------------*/ /* AU1200 LCD device probe helpers */ static int au1200fb_init_fbinfo(struct au1200fb_device *fbdev) { struct fb_info *fbi = &fbdev->fb_info; int bpp; memset(fbi, 0, sizeof(struct fb_info)); fbi->fbops = &au1200fb_fb_ops; bpp = winbpp(win->w[fbdev->plane].mode_winctrl1); /* Copy monitor specs from panel data */ /* fixme: we're setting up LCD controller windows, so these dont give a damn as to what the monitor specs are (the panel itself does, but that isnt done here...so maybe need a generic catchall monitor setting??? */ memcpy(&fbi->monspecs, &panel->monspecs, sizeof(struct fb_monspecs)); /* We first try the user mode passed in argument. If that failed, * or if no one has been specified, we default to the first mode of the * panel list. Note that after this call, var data will be set */ if (!fb_find_mode(&fbi->var, fbi, NULL, /* drv_info.opt_mode, */ fbi->monspecs.modedb, fbi->monspecs.modedb_len, fbi->monspecs.modedb, bpp)) { print_err("Cannot find valid mode for panel %s", panel->name); return -EFAULT; } fbi->pseudo_palette = kcalloc(16, sizeof(u32), GFP_KERNEL); if (!fbi->pseudo_palette) { return -ENOMEM; } if (fb_alloc_cmap(&fbi->cmap, AU1200_LCD_NBR_PALETTE_ENTRIES, 0) < 0) { print_err("Fail to allocate colormap (%d entries)", AU1200_LCD_NBR_PALETTE_ENTRIES); kfree(fbi->pseudo_palette); return -EFAULT; } strncpy(fbi->fix.id, "AU1200", sizeof(fbi->fix.id)); fbi->fix.smem_start = fbdev->fb_phys; fbi->fix.smem_len = fbdev->fb_len; fbi->fix.type = FB_TYPE_PACKED_PIXELS; fbi->fix.xpanstep = 0; fbi->fix.ypanstep = 0; fbi->fix.mmio_start = 0; fbi->fix.mmio_len = 0; fbi->fix.accel = FB_ACCEL_NONE; fbi->screen_base = (char __iomem *) fbdev->fb_mem; au1200fb_update_fbinfo(fbi); return 0; } /*-------------------------------------------------------------------------*/ /* AU1200 LCD controller device driver */ static int au1200fb_drv_probe(struct device *dev) { struct au1200fb_device *fbdev; unsigned long page; int bpp, plane, ret; if (!dev) return -EINVAL; for (plane = 0; plane < CONFIG_FB_AU1200_DEVS; ++plane) { bpp = winbpp(win->w[plane].mode_winctrl1); if (win->w[plane].xres == 0) win->w[plane].xres = panel->Xres; if (win->w[plane].yres == 0) win->w[plane].yres = panel->Yres; fbdev = &_au1200fb_devices[plane]; memset(fbdev, 0, sizeof(struct au1200fb_device)); fbdev->plane = plane; /* Allocate the framebuffer to the maximum screen size */ fbdev->fb_len = (win->w[plane].xres * win->w[plane].yres * bpp) / 8; fbdev->fb_mem = dma_alloc_noncoherent(dev, PAGE_ALIGN(fbdev->fb_len), &fbdev->fb_phys, GFP_KERNEL); if (!fbdev->fb_mem) { print_err("fail to allocate frambuffer (size: %dK))", fbdev->fb_len / 1024); return -ENOMEM; } /* * Set page reserved so that mmap will work. This is necessary * since we'll be remapping normal memory. */ for (page = (unsigned long)fbdev->fb_phys; page < PAGE_ALIGN((unsigned long)fbdev->fb_phys + fbdev->fb_len); page += PAGE_SIZE) {