summaryrefslogtreecommitdiffstats
path: root/sys/powerpc/wii/wii_fbvar.h
blob: 53e71dfa5b810364d58e133a1033f2e9ff5242df (plain)
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
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
/*-
 * Copyright (C) 2012 Margarida Gouveia
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer,
 *    without modification, immediately at the beginning of the file.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * $FreeBSD$
 */

#ifndef	_POWERPC_WII_WIIFB_H
#define	_POWERPC_WII_WIIFB_H

#define	WIIFB_FONT_HEIGHT	8

enum wiifb_format {
	WIIFB_FORMAT_NTSC  = 0,
	WIIFB_FORMAT_PAL   = 1,
	WIIFB_FORMAT_MPAL  = 2,
	WIIFB_FORMAT_DEBUG = 3
};

enum wiifb_mode {
	WIIFB_MODE_NTSC_480i = 0,
	WIIFB_MODE_NTSC_480p = 1,
	WIIFB_MODE_PAL_576i  = 2,
	WIIFB_MODE_PAL_480i  = 3,
	WIIFB_MODE_PAL_480p  = 4
};

struct wiifb_mode_desc {
	const char 	*fd_name;
	unsigned int	fd_width;
	unsigned int	fd_height;
	unsigned int	fd_lines;
	uint8_t		fd_flags;
#define WIIFB_MODE_FLAG_PROGRESSIVE	0x00
#define WIIFB_MODE_FLAG_INTERLACED	0x01
};

struct wiifb_softc {
	video_adapter_t	sc_va;
	struct cdev	*sc_si;
	int		sc_console;

	intptr_t	sc_reg_addr;
	unsigned int	sc_reg_size;

	intptr_t	sc_fb_addr;
	unsigned int	sc_fb_size;

	unsigned int	sc_height;
	unsigned int	sc_width;
	unsigned int	sc_stride;

	unsigned int	sc_xmargin;
	unsigned int	sc_ymargin;

	boolean_t	sc_component;
	enum wiifb_format sc_format;
	struct wiifb_mode_desc *sc_mode;

	unsigned int	sc_vtiming;
	unsigned int	sc_htiming;

	unsigned char	*sc_font;
	int		sc_initialized;
	int		sc_rrid;
};

/*
 * Vertical timing
 * 16 bit
 */
#define	WIIFB_REG_VTIMING	0x00
struct wiifb_vtiming {
	uint8_t		vt_eqpulse;
	uint16_t	vt_actvideo;
};

static __inline void
wiifb_vtiming_read(struct wiifb_softc *sc, struct wiifb_vtiming *vt)
{
	volatile uint16_t *reg =
	    (uint16_t *)(sc->sc_reg_addr + WIIFB_REG_VTIMING);
	
	vt->vt_eqpulse  = *reg & 0xf;
	vt->vt_actvideo = (*reg >> 4) & 0x3ff;
}

static __inline void
wiifb_vtiming_write(struct wiifb_softc *sc, struct wiifb_vtiming *vt)
{
	volatile uint16_t *reg =
	    (uint16_t *)(sc->sc_reg_addr + WIIFB_REG_VTIMING);

	*reg = ((vt->vt_actvideo & 0x3ff) << 4) |
	        (vt->vt_eqpulse & 0xf);
	powerpc_sync();
}

/*
 * Display configuration
 * 16 bit
 */
#define	WIIFB_REG_DISPCFG	0x02
struct wiifb_dispcfg {
	uint8_t		  dc_enable;
	uint8_t		  dc_reset;
	uint8_t		  dc_noninterlaced;
	uint8_t		  dc_3dmode;
	uint8_t		  dc_latchenb0;
	uint8_t		  dc_latchenb1;
	enum wiifb_format dc_format;
};

static __inline void
wiifb_dispcfg_read(struct wiifb_softc *sc, struct wiifb_dispcfg *dc)
{
	volatile uint16_t *reg =
	    (uint16_t *)(sc->sc_reg_addr + WIIFB_REG_DISPCFG);

	dc->dc_enable        = *reg & 0x1;
	dc->dc_reset         = (*reg >> 1) & 0x1;
	dc->dc_noninterlaced = (*reg >> 2) & 0x1;
	dc->dc_3dmode        = (*reg >> 3) & 0x1;
	dc->dc_latchenb0     = (*reg >> 4) & 0x3;
	dc->dc_latchenb1     = (*reg >> 6) & 0x3;
	dc->dc_format        = (*reg >> 8) & 0x3;
}

static __inline void
wiifb_dispcfg_write(struct wiifb_softc *sc, struct wiifb_dispcfg *dc)
{
	volatile uint16_t *reg =
	    (uint16_t *)(sc->sc_reg_addr + WIIFB_REG_DISPCFG);

	*reg = ((dc->dc_format & 0x3) << 8)        |
	       ((dc->dc_latchenb1 & 0x3) << 6)     |
	       ((dc->dc_latchenb0 & 0x3) << 4)     |
	       ((dc->dc_3dmode & 0x1) << 3)        |
	       ((dc->dc_noninterlaced & 0x1) << 2) |
	       ((dc->dc_reset & 0x1) << 1)         |
	        (dc->dc_enable & 0x1);
	powerpc_sync();
}

/*
 * Horizontal Timing 0
 * 32 bit
 */
#define	WIIFB_REG_HTIMING0		0x04
struct wiifb_htiming0 {
	uint16_t	ht0_hlinew;	/* half line width */
	uint8_t		ht0_hcolourend;
	uint8_t		ht0_hcolourstart;
};

static __inline void
wiifb_htiming0_read(struct wiifb_softc *sc, struct wiifb_htiming0 *ht0)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_HTIMING0);

	ht0->ht0_hlinew       = *reg & 0x1ff;
	ht0->ht0_hcolourend   = (*reg >> 16) & 0x7f;
	ht0->ht0_hcolourstart = (*reg >> 24) & 0x7f;
}

static __inline void
wiifb_htiming0_write(struct wiifb_softc *sc, struct wiifb_htiming0 *ht0)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_HTIMING0);

	*reg = ((ht0->ht0_hcolourstart & 0x7f) << 24) |
	       ((ht0->ht0_hcolourend & 0x7f) << 16)   |
	        (ht0->ht0_hlinew & 0x1ff);
	powerpc_sync();
}
/*
 * Horizontal Timing 1
 * 32 bit
 */
#define	WIIFB_REG_HTIMING1		0x08
struct wiifb_htiming1 {
	uint8_t		ht1_hsyncw;
	uint16_t	ht1_hblankend;
	uint16_t	ht1_hblankstart;
};

static __inline void
wiifb_htiming1_read(struct wiifb_softc *sc, struct wiifb_htiming1 *ht1)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_HTIMING1);

	ht1->ht1_hsyncw      = *reg & 0x7f;
	ht1->ht1_hblankend   = (*reg >> 7) & 0x3ff;
	ht1->ht1_hblankstart = (*reg >> 17) & 0x3ff;
}

static __inline void
wiifb_htiming1_write(struct wiifb_softc *sc, struct wiifb_htiming1 *ht1)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_HTIMING1);

	*reg = ((ht1->ht1_hblankstart & 0x3ff) << 17) |
	       ((ht1->ht1_hblankend & 0x3ff) << 7)    |
	        (ht1->ht1_hsyncw & 0x7f);
	powerpc_sync();
}

/*
 * Vertical Timing Odd
 * 32 bit
 */
#define	WIIFB_REG_VTIMINGODD		0x0c
struct wiifb_vtimingodd {
	uint16_t	vto_preb;	/* pre blanking */
	uint16_t	vto_postb;	/* post blanking */
};

static __inline void
wiifb_vtimingodd_read(struct wiifb_softc *sc, struct wiifb_vtimingodd *vto)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_VTIMINGODD);

	vto->vto_preb  = *reg & 0x3ff;
	vto->vto_postb = (*reg >> 16) & 0x3ff;
}

static __inline void
wiifb_vtimingodd_write(struct wiifb_softc *sc, struct wiifb_vtimingodd *vto)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_VTIMINGODD);

	*reg = ((vto->vto_postb & 0x3ff) << 16) | 
	        (vto->vto_preb & 0x3ff);
	powerpc_sync();
}

/*
 * Vertical Timing Even
 * 32 bit
 */
#define	WIIFB_REG_VTIMINGEVEN		0x10
struct wiifb_vtimingeven {
	uint16_t	vte_preb;	/* pre blanking */
	uint16_t	vte_postb;	/* post blanking */
};

static __inline void
wiifb_vtimingeven_read(struct wiifb_softc *sc, struct wiifb_vtimingeven *vte)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_VTIMINGEVEN);

	vte->vte_preb  = *reg & 0x3ff;
	vte->vte_postb = (*reg >> 16) & 0x3ff;
}

static __inline void
wiifb_vtimingeven_write(struct wiifb_softc *sc, struct wiifb_vtimingeven *vte)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_VTIMINGEVEN);

	*reg = ((vte->vte_postb & 0x3ff) << 16) | 
	        (vte->vte_preb & 0x3ff);
	powerpc_sync();
}

/*
 * Burst Blanking Odd Interval
 * 32 bit
 */
#define	WIIFB_REG_BURSTBLANKODD		0x14
struct wiifb_burstblankodd {
	uint8_t		bbo_bs1;
	uint16_t	bbo_be1;
	uint8_t		bbo_bs3;
	uint16_t	bbo_be3;
};

static __inline void
wiifb_burstblankodd_read(struct wiifb_softc *sc,
    struct wiifb_burstblankodd *bbo)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_BURSTBLANKODD);

	bbo->bbo_bs1 = *reg & 0x1f;
	bbo->bbo_be1 = (*reg >> 5) & 0x7ff;
	bbo->bbo_bs3 = (*reg >> 16) & 0x1f;
	bbo->bbo_be3 = (*reg >> 21) & 0x7ff;
}

static __inline void
wiifb_burstblankodd_write(struct wiifb_softc *sc,
    struct wiifb_burstblankodd *bbo)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_BURSTBLANKODD);

	*reg = ((bbo->bbo_be3 & 0x7ff) << 21) |
	       ((bbo->bbo_bs3 & 0x1f) << 16)  |
	       ((bbo->bbo_be1 & 0x7ff) << 5)  |
	        (bbo->bbo_bs1 & 0x1f);
	powerpc_sync();
}

/*
 * Burst Blanking Even Interval
 * 32 bit
 */
#define	WIIFB_REG_BURSTBLANKEVEN	0x18
struct wiifb_burstblankeven {
	uint8_t		bbe_bs2;
	uint16_t	bbe_be2;
	uint8_t		bbe_bs4;
	uint16_t	bbe_be4;
};

static __inline void
wiifb_burstblankeven_read(struct wiifb_softc *sc,
    struct wiifb_burstblankeven *bbe)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_BURSTBLANKEVEN);

	bbe->bbe_bs2 = *reg & 0x1f;
	bbe->bbe_be2 = (*reg >> 5) & 0x7ff;
	bbe->bbe_bs4 = (*reg >> 16) & 0x1f;
	bbe->bbe_be4 = (*reg >> 21) & 0x7ff;
}

static __inline void
wiifb_burstblankeven_write(struct wiifb_softc *sc,
    struct wiifb_burstblankeven *bbe)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_BURSTBLANKEVEN);

	*reg = ((bbe->bbe_be4 & 0x7ff) << 21) |
	       ((bbe->bbe_bs4 & 0x1f) << 16)  |
	       ((bbe->bbe_be2 & 0x7ff) << 5)  |
	        (bbe->bbe_bs2 & 0x1f);
	powerpc_sync();
}

/*
 * Top Field Base Left
 * 32 bit
 */
#define	WIIFB_REG_TOPFIELDBASEL		0x1c
struct wiifb_topfieldbasel {
	uint32_t	tfbl_fbaddr;
	uint8_t		tfbl_xoffset;
	uint8_t		tfbl_pageoffbit;
};

static __inline void
wiifb_topfieldbasel_read(struct wiifb_softc *sc,
    struct wiifb_topfieldbasel *tfbl)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_TOPFIELDBASEL);

	tfbl->tfbl_fbaddr     = *reg & 0xffffff;
	tfbl->tfbl_xoffset    = (*reg >> 24) & 0xf;
	tfbl->tfbl_pageoffbit = (*reg >> 28) & 0x1;
}

static __inline void
wiifb_topfieldbasel_write(struct wiifb_softc *sc,
    struct wiifb_topfieldbasel *tfbl)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_TOPFIELDBASEL);

	*reg = ((tfbl->tfbl_pageoffbit & 0x1) << 28) |
	       ((tfbl->tfbl_xoffset & 0xf) << 24)    |
	        (tfbl->tfbl_fbaddr & 0xffffff);
	powerpc_sync();
}

/*
 * Top Field Base Right
 * 32 bit
 */
#define	WIIFB_REG_TOPFIELDBASER		0x20
struct wiifb_topfieldbaser {
	uint32_t	tfbr_fbaddr;
	uint8_t		tfbr_pageoffbit;
};

static __inline void
wiifb_topfieldbaser_read(struct wiifb_softc *sc,
    struct wiifb_topfieldbaser *tfbr)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_TOPFIELDBASER);

	tfbr->tfbr_fbaddr     = *reg & 0xffffff;
	tfbr->tfbr_pageoffbit = (*reg >> 28) & 0x1;
}

static __inline void
wiifb_topfieldbaser_write(struct wiifb_softc *sc,
    struct wiifb_topfieldbaser *tfbr)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_TOPFIELDBASER);

	*reg  = ((tfbr->tfbr_pageoffbit & 0x1) << 28) |
		 (tfbr->tfbr_fbaddr & 0xffffff);
	powerpc_sync();
}

/*
 * Bottom Field Base Left
 * 32 bit
 */
#define	WIIFB_REG_BOTTOMFIELDBASEL	0x24
struct wiifb_bottomfieldbasel {
	uint32_t	bfbl_fbaddr;
	uint8_t		bfbl_xoffset;
	uint8_t		bfbl_pageoffbit;
};

static __inline void
wiifb_bottomfieldbasel_read(struct wiifb_softc *sc,
    struct wiifb_bottomfieldbasel *bfbl)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_BOTTOMFIELDBASEL);

	bfbl->bfbl_fbaddr     = *reg & 0xffffff;
	bfbl->bfbl_xoffset    = (*reg >> 24) & 0xf;
	bfbl->bfbl_pageoffbit = (*reg >> 28) & 0x1;
}

static __inline void
wiifb_bottomfieldbasel_write(struct wiifb_softc *sc,
    struct wiifb_bottomfieldbasel *bfbl)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_BOTTOMFIELDBASEL);

	*reg  = ((bfbl->bfbl_pageoffbit & 0x1) << 28) |
	        ((bfbl->bfbl_xoffset & 0xf) << 24)    |
		 (bfbl->bfbl_fbaddr & 0xffffff);
	powerpc_sync();
}

/*
 * Bottom Field Base Right
 * 32 bit
 */
#define	WIIFB_REG_BOTTOMFIELDBASER	0x28
struct wiifb_bottomfieldbaser {
	uint32_t	bfbr_fbaddr;
	uint8_t		bfbr_pageoffbit;
};

static __inline void
wiifb_bottomfieldbaser_read(struct wiifb_softc *sc,
    struct wiifb_bottomfieldbaser *bfbr)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_BOTTOMFIELDBASER);

	bfbr->bfbr_fbaddr     = *reg & 0xffffff;
	bfbr->bfbr_pageoffbit = (*reg >> 28) & 0x1;
}

static __inline void
wiifb_bottomfieldbaser_write(struct wiifb_softc *sc,
    struct wiifb_bottomfieldbaser *bfbr)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_BOTTOMFIELDBASER);

	*reg  = ((bfbr->bfbr_pageoffbit & 0x1) << 28) |
		 (bfbr->bfbr_fbaddr & 0xffffff);
	powerpc_sync();
}

/*
 * Display Position Vertical
 * 16 bit
 */
#define	WIIFB_REG_DISPPOSV		0x2c
static __inline uint16_t
wiifb_dispposv_read(struct wiifb_softc *sc)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_DISPPOSV);

	return (*reg & 0x7ff);
}

static __inline void
wiifb_dispposv_write(struct wiifb_softc *sc, uint16_t val)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_DISPPOSV);

	*reg = val & 0x7ff;
	powerpc_sync();
}

/*
 * Display Position Horizontal
 * 16 bit
 */
#define	WIIFB_REG_DISPPOSH		0x2e
static __inline uint16_t
wiifb_dispposh_read(struct wiifb_softc *sc)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_DISPPOSH);

	return (*reg & 0x7ff);
}

static __inline void
wiifb_dispposh_write(struct wiifb_softc *sc, uint16_t val)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_DISPPOSH);

	*reg = val & 0x7ff;
	powerpc_sync();
}

/*
 * Display Interrupts.
 * There are 4 display interrupt registers, all 32 bit.
 */
#define	WIIFB_REG_DISPINT0		0x30
#define	WIIFB_REG_DISPINT1		0x34
#define	WIIFB_REG_DISPINT2		0x38
#define	WIIFB_REG_DISPINT3		0x3c
struct wiifb_dispint {
	uint16_t	di_htiming;
	uint16_t	di_vtiming;
	uint8_t		di_enable;
	uint8_t		di_irq;
};

static __inline void
wiifb_dispint_read(struct wiifb_softc *sc, int regno, struct wiifb_dispint *di)
{
	volatile uint32_t *reg = (uint32_t *)(sc->sc_reg_addr +
	    WIIFB_REG_DISPINT0 + regno * 4);

	di->di_htiming = *reg & 0x3ff;
	di->di_vtiming = (*reg >> 16) & 0x3ff;
	di->di_enable   = (*reg >> 28) & 0x1;
	di->di_irq      = (*reg >> 31) & 0x1;
}

static __inline void
wiifb_dispint_write(struct wiifb_softc *sc, int regno, struct wiifb_dispint *di)
{
	volatile uint32_t *reg = (uint32_t *)(sc->sc_reg_addr +
	    WIIFB_REG_DISPINT0 + regno * 4);

	*reg = ((di->di_irq & 0x1) << 31)        |
	       ((di->di_enable & 0x1) << 28)     |
	       ((di->di_vtiming & 0x3ff) << 16)  |
	        (di->di_htiming & 0x3ff);
	powerpc_sync();
}

/*
 * Display Latch 0
 * 32 bit
 */
#define	WIIFB_REG_DISPLAYTCH0		0x40

/*
 * Display Latch 1
 * 32 bit
 */
#define	WIIFB_REG_DISPLAYTCH1		0x44

/*
 * Picture Configuration
 * 16 bit
 */
#define	WIIFB_REG_PICCONF		0x48
struct wiifb_picconf {
	uint8_t		pc_strides;	/* strides per line (words) */
	uint8_t		pc_reads;	/* reads per line (words */
};

static __inline void
wiifb_picconf_read(struct wiifb_softc *sc, struct wiifb_picconf *pc)
{
	volatile uint16_t *reg =
	    (uint16_t *)(sc->sc_reg_addr + WIIFB_REG_PICCONF);

	pc->pc_strides = *reg & 0xff;
	pc->pc_reads   = (*reg >> 8) & 0xff;
}

static __inline void
wiifb_picconf_write(struct wiifb_softc *sc, struct wiifb_picconf *pc)
{
	volatile uint16_t *reg =
	    (uint16_t *)(sc->sc_reg_addr + WIIFB_REG_PICCONF);

	*reg = ((pc->pc_reads & 0xff) << 8) |
	        (pc->pc_strides & 0xff);
	powerpc_sync();
}

/*
 * Horizontal Scaling
 * 16 bit
 */
#define	WIIFB_REG_HSCALING		0x4a
struct wiifb_hscaling {
	uint16_t	hs_step;
	uint8_t		hs_enable;
};

static __inline void
wiifb_hscaling_read(struct wiifb_softc *sc, struct wiifb_hscaling *hs)
{
	volatile uint16_t *reg =
	    (uint16_t *)(sc->sc_reg_addr + WIIFB_REG_HSCALING);

	hs->hs_step   = *reg & 0x1ff;
	hs->hs_enable = (*reg >> 12) & 0x1;
}

static __inline void
wiifb_hscaling_write(struct wiifb_softc *sc, struct wiifb_hscaling *hs)
{
	volatile uint16_t *reg =
	    (uint16_t *)(sc->sc_reg_addr + WIIFB_REG_HSCALING);

	*reg = ((hs->hs_step & 0x1ff) << 12) |
	        (hs->hs_enable & 0x1);
	powerpc_sync();
}

/*
 * Filter Coeficient Table 0-6
 * 32 bit
 */
#define	WIIFB_REG_FILTCOEFT0		0x4c
#define	WIIFB_REG_FILTCOEFT1		0x50
#define	WIIFB_REG_FILTCOEFT2		0x54
#define	WIIFB_REG_FILTCOEFT3		0x58
#define	WIIFB_REG_FILTCOEFT4		0x5c
#define	WIIFB_REG_FILTCOEFT5		0x60
#define	WIIFB_REG_FILTCOEFT6		0x64
static __inline void
wiifb_filtcoeft_write(struct wiifb_softc *sc, unsigned int regno,
    uint32_t coeft)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_FILTCOEFT0 + 4 * regno);

	*reg = coeft;
	powerpc_sync();
}

/*
 * Anti-aliasing
 * 32 bit
 */
#define	WIIFB_REG_ANTIALIAS		0x68
static __inline void
wiifb_antialias_write(struct wiifb_softc *sc, uint32_t antialias)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_ANTIALIAS);

	*reg = antialias;
	powerpc_sync();
}

/*
 * Video Clock
 * 16 bit
 */
#define	WIIFB_REG_VIDEOCLK		0x6c
static __inline uint8_t
wiifb_videoclk_read(struct wiifb_softc *sc)
{
	volatile uint16_t *reg =
	    (uint16_t *)(sc->sc_reg_addr + WIIFB_REG_VIDEOCLK);

	return (*reg & 0x1);
}

static __inline void
wiifb_videoclk_write(struct wiifb_softc *sc, uint16_t clk54mhz)
{
	volatile uint16_t *reg =
	    (uint16_t *)(sc->sc_reg_addr + WIIFB_REG_VIDEOCLK);

	*reg = clk54mhz & 0x1;
	powerpc_sync();
}

/*
 * DTV Status
 * 16 bit
 *
 * DTV is another name for the Component Cable output.
 */
#define	WIIFB_REG_DTVSTATUS		0x6e
static __inline uint16_t
wiifb_dtvstatus_read(struct wiifb_softc *sc)
{
	volatile uint16_t *reg =
	    (uint16_t *)(sc->sc_reg_addr + WIIFB_REG_DTVSTATUS);

	return (*reg & 0x1);
}

static __inline uint16_t
wiifb_component_enabled(struct wiifb_softc *sc)
{
	
	return wiifb_dtvstatus_read(sc);
}

/*
 * Horizontal Scaling Width
 * 16 bit
 */
#define	WIIFB_REG_HSCALINGW		0x70
static __inline uint16_t
wiifb_hscalingw_read(struct wiifb_softc *sc)
{
	volatile uint16_t *reg =
	    (uint16_t *)(sc->sc_reg_addr + WIIFB_REG_HSCALINGW);

	return (*reg & 0x3ff);
}

static __inline void
wiifb_hscalingw_write(struct wiifb_softc *sc, uint16_t width)
{
	volatile uint16_t *reg =
	    (uint16_t *)(sc->sc_reg_addr + WIIFB_REG_HSCALINGW);

	*reg = width & 0x3ff;
	powerpc_sync();
}

/* 
 * Horizontal Border End
 * For debug mode only. Not used by this driver.
 * 16 bit
 */
#define	WIIFB_REG_HBORDEREND		0x72
static __inline void
wiifb_hborderend_write(struct wiifb_softc *sc, uint16_t border)
{
	volatile uint16_t *reg =
	    (uint16_t *)(sc->sc_reg_addr + WIIFB_REG_HBORDEREND);

	*reg = border;
	powerpc_sync();
}

/* 
 * Horizontal Border Start
 * 16 bit
 */
#define	WIIFB_REG_HBORDERSTART		0x74
static __inline void
wiifb_hborderstart_write(struct wiifb_softc *sc, uint16_t border)
{
	volatile uint16_t *reg =
	    (uint16_t *)(sc->sc_reg_addr + WIIFB_REG_HBORDERSTART);

	*reg = border;
	powerpc_sync();
}

/*
 * Unknown register
 * 16 bit
 */
#define	WIIFB_REG_UNKNOWN1		0x76
static __inline void
wiifb_unknown1_write(struct wiifb_softc *sc, uint16_t unknown)
{
	volatile uint16_t *reg =
	    (uint16_t *)(sc->sc_reg_addr + WIIFB_REG_UNKNOWN1);

	*reg = unknown;
	powerpc_sync();
}

/* 
 * Unknown register
 * 32 bit
 */
#define	WIIFB_REG_UNKNOWN2		0x78
static __inline void
wiifb_unknown2_write(struct wiifb_softc *sc, uint32_t unknown)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_UNKNOWN2);

	*reg = unknown;
	powerpc_sync();
}

/*
 * Unknown register
 * 32 bit
 */
#define	WIIFB_REG_UNKNOWN3		0x7c
static __inline void
wiifb_unknown3_write(struct wiifb_softc *sc, uint32_t unknown)
{
	volatile uint32_t *reg =
	    (uint32_t *)(sc->sc_reg_addr + WIIFB_REG_UNKNOWN3);

	*reg = unknown;
	powerpc_sync();
}

#endif /* _POWERPC_WII_WIIFB_H */
OpenPOWER on IntegriCloud